package c.j.a.c;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Build.VERSION;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import c.j.a.c.q.d;
import c.j.a.d.a.i;
import c.j.a.d.b.n.d0;
import com.huawei.agconnect.exception.AGCServerException;
import com.huawei.hms.adapter.internal.BaseCode;
import com.huawei.hms.support.api.entity.common.CommonConstant.ACTION;
import com.ss.android.downloadlib.activity.TTDelegateActivity;
import com.ss.android.socialbase.appdownloader.DownloadHandlerService;
import java.io.File;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: AdDownloadCompletedEventHandlerImpl */
public class g implements c.j.a.b.a.b, c.j.a.d.a.g.c, c.j.a.d.b.a.a.b {
    public static String c = "g";
    public static volatile g d;
    public long a;
    public b b;

    /* compiled from: AdDownloadCompletedEventHandlerImpl */
    public class a implements Runnable {
        public final int a;

        public a(int i) {
            this.a = i;
        }

        public void run() {
            try {
                c.j.a.c.g$g.d.c.a.f();
                ConcurrentHashMap concurrentHashMap = c.j.a.c.g$g.d.c.a.e;
                if (concurrentHashMap != null && !concurrentHashMap.isEmpty()) {
                    g.i(g.this, concurrentHashMap, this.a);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /* compiled from: AdDownloadCompletedEventHandlerImpl */
    public static class b implements Runnable {
        public long a;
        public int b;
        public long c;
        public int d;
        public long e;

        public b(long j, int i, long j2, int i2, e eVar) {
            this.a = j;
            this.b = i;
            this.c = j2;
            this.d = i2;
        }

        /* JADX WARNING: Removed duplicated region for block: B:78:0x013f  */
        /* JADX WARNING: Removed duplicated region for block: B:55:0x0108 A:{Catch:{ all -> 0x010b }} */
        /* JADX WARNING: Removed duplicated region for block: B:59:0x0112 A:{SKIP} */
        /* JADX WARNING: Removed duplicated region for block: B:78:0x013f  */
        /* JADX WARNING: Removed duplicated region for block: B:98:0x019a A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:102:0x01ac A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:101:0x01aa A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:110:0x01ca A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:109:0x01c8 A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:113:0x01d8 A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:34:0x00b8  */
        /* JADX WARNING: Removed duplicated region for block: B:27:0x0092  */
        /* JADX WARNING: Removed duplicated region for block: B:38:0x00c5  */
        /* JADX WARNING: Removed duplicated region for block: B:37:0x00c2  */
        /* JADX WARNING: Removed duplicated region for block: B:98:0x019a A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:101:0x01aa A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:102:0x01ac A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:109:0x01c8 A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:110:0x01ca A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:113:0x01d8 A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:27:0x0092  */
        /* JADX WARNING: Removed duplicated region for block: B:34:0x00b8  */
        /* JADX WARNING: Removed duplicated region for block: B:37:0x00c2  */
        /* JADX WARNING: Removed duplicated region for block: B:38:0x00c5  */
        /* JADX WARNING: Removed duplicated region for block: B:98:0x019a A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:102:0x01ac A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:101:0x01aa A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:110:0x01ca A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:109:0x01c8 A:{Catch:{ Exception -> 0x01dd }} */
        /* JADX WARNING: Removed duplicated region for block: B:113:0x01d8 A:{Catch:{ Exception -> 0x01dd }} */
        public boolean a() {
            /*
            r20 = this;
            r1 = r20;
            r0 = c.j.a.c.g$g.d.c.a;
            r2 = r1.a;
            r2 = r0.g(r2);
            r3 = 0;
            if (r2 == 0) goto L_0x01ea;
        L_0x000d:
            r0 = c.j.a.c.q.d.o(r2);
            if (r0 != 0) goto L_0x01ea;
        L_0x0013:
            r0 = r2.J;
            r0 = r0.get();
            if (r0 == 0) goto L_0x001d;
        L_0x001b:
            goto L_0x01ea;
        L_0x001d:
            r0 = c.j.a.c.g.y.a();
            r0 = c.j.a.d.b.e.i.a(r0);
            r4 = r2.q;
            r4 = r0.k(r4);
            if (r4 != 0) goto L_0x002e;
        L_0x002d:
            return r3;
        L_0x002e:
            r5 = r2.L;
            r0 = android.os.Environment.getDataDirectory();
            r7 = -1;
            if (r0 != 0) goto L_0x0039;
        L_0x0038:
            goto L_0x004b;
        L_0x0039:
            r9 = new android.os.StatFs;	 Catch:{ all -> 0x0047 }
            r0 = r0.getAbsolutePath();	 Catch:{ all -> 0x0047 }
            r9.<init>(r0);	 Catch:{ all -> 0x0047 }
            r9 = r9.getTotalBytes();	 Catch:{ all -> 0x0047 }
            goto L_0x004c;
        L_0x0047:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x004b:
            r9 = r7;
        L_0x004c:
            r11 = 524288000; // 0x1f400000 float:4.065758E-20 double:2.590326893E-315;
            r13 = 10;
            r13 = r9 / r13;
            r11 = java.lang.Math.min(r11, r13);
            r13 = r4.T;
            r15 = 1;
            r0 = (r5 > r7 ? 1 : (r5 == r7 ? 0 : -1));
            if (r0 <= 0) goto L_0x0072;
        L_0x005e:
            r0 = (r13 > r7 ? 1 : (r13 == r7 ? 0 : -1));
            if (r0 <= 0) goto L_0x0072;
        L_0x0062:
            r7 = (double) r5;
            r11 = (double) r11;
            r16 = r4;
            r3 = (double) r13;
            r17 = 4612811918334230528; // 0x4004000000000000 float:0.0 double:2.5;
            r3 = r3 * r17;
            r3 = r3 + r11;
            r0 = (r7 > r3 ? 1 : (r7 == r3 ? 0 : -1));
            if (r0 >= 0) goto L_0x0074;
        L_0x0070:
            r3 = 0;
            goto L_0x0075;
        L_0x0072:
            r16 = r4;
        L_0x0074:
            r3 = 1;
        L_0x0075:
            r0 = c.j.a.c.g.y.a();
            r4 = c.j.a.d.a.g.e(r0);
            r7 = new org.json.JSONObject;
            r7.<init>();
            r0 = r16.g0();
            r0 = c.j.a.d.b.l.a.d(r0);
            r8 = "install_failed_check_ttmd5";
            r8 = r0.b(r8, r15);
            if (r8 != r15) goto L_0x00b8;
        L_0x0092:
            r8 = r16;
            r11 = r8.e;
            r12 = r8.b;
            r15 = r8.y;
            r17 = c.j.a.d.b.n.a.a;
            r18 = r13;
            r13 = new java.io.File;
            r13.<init>(r11, r12);
            r11 = c.j.a.e.b.b(r15, r13);
            r12 = "ttmd5_status";
            r7.put(r12, r11);	 Catch:{ all -> 0x00ad }
            goto L_0x00ae;
        L_0x00ae:
            r11 = c.j.a.d.b.n.a.s(r11);
            if (r11 != 0) goto L_0x00bc;
        L_0x00b4:
            r0 = 2005; // 0x7d5 float:2.81E-42 double:9.906E-321;
            goto L_0x0171;
        L_0x00b8:
            r18 = r13;
            r8 = r16;
        L_0x00bc:
            r11 = r1.d;
            r12 = 2000; // 0x7d0 float:2.803E-42 double:9.88E-321;
            if (r11 == r12) goto L_0x00c5;
        L_0x00c2:
            r0 = r11;
            goto L_0x0171;
        L_0x00c5:
            r11 = "install_failed_check_signature";
            r13 = 1;
            r0 = r0.b(r11, r13);
            if (r0 != r13) goto L_0x0142;
        L_0x00ce:
            r0 = c.j.a.c.g.y.a();
            r11 = r2.e;
            r0 = c.j.a.c.q.d.p(r0, r11);
            if (r0 == 0) goto L_0x0142;
        L_0x00da:
            r0 = c.j.a.c.g.y.a();
            r11 = r2.e;
            r13 = 0;
            r14 = 64;
            r0 = r0.getPackageManager();	 Catch:{ all -> 0x00f1 }
            r0 = r0.getPackageInfo(r11, r14);	 Catch:{ all -> 0x00f1 }
            if (r0 == 0) goto L_0x00f5;
        L_0x00ed:
            r0 = r0.signatures;	 Catch:{ all -> 0x00f1 }
            r11 = r0;
            goto L_0x00f6;
        L_0x00f1:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x00f5:
            r11 = r13;
        L_0x00f6:
            r0 = c.j.a.c.g.y.a();
            r8 = r8.m0();
            r0 = r0.getPackageManager();	 Catch:{ all -> 0x010b }
            r0 = r0.getPackageArchiveInfo(r8, r14);	 Catch:{ all -> 0x010b }
            if (r0 == 0) goto L_0x010f;
        L_0x0108:
            r13 = r0.signatures;	 Catch:{ all -> 0x010b }
            goto L_0x010f;
        L_0x010b:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x010f:
            if (r13 != r11) goto L_0x0112;
        L_0x0111:
            goto L_0x013a;
        L_0x0112:
            if (r13 == 0) goto L_0x013c;
        L_0x0114:
            if (r11 != 0) goto L_0x0117;
        L_0x0116:
            goto L_0x013c;
        L_0x0117:
            r0 = r13.length;
            r8 = r11.length;
            if (r0 == r8) goto L_0x011c;
        L_0x011b:
            goto L_0x013c;
        L_0x011c:
            r0 = 0;
        L_0x011d:
            r8 = r13.length;
            if (r0 >= r8) goto L_0x013a;
        L_0x0120:
            r8 = r13[r0];
            if (r8 != 0) goto L_0x0128;
        L_0x0124:
            r8 = r11[r0];
            if (r8 != 0) goto L_0x013c;
        L_0x0128:
            r8 = r13[r0];
            if (r8 == 0) goto L_0x0137;
        L_0x012c:
            r8 = r13[r0];
            r14 = r11[r0];
            r8 = r8.equals(r14);
            if (r8 != 0) goto L_0x0137;
        L_0x0136:
            goto L_0x013c;
        L_0x0137:
            r0 = r0 + 1;
            goto L_0x011d;
        L_0x013a:
            r13 = 1;
            goto L_0x013d;
        L_0x013c:
            r13 = 0;
        L_0x013d:
            if (r13 != 0) goto L_0x0142;
        L_0x013f:
            r0 = 2006; // 0x7d6 float:2.811E-42 double:9.91E-321;
            goto L_0x0171;
        L_0x0142:
            if (r3 != 0) goto L_0x0147;
        L_0x0144:
            r0 = 2002; // 0x7d2 float:2.805E-42 double:9.89E-321;
            goto L_0x0171;
        L_0x0147:
            r13 = r1.e;
            r11 = r1.c;
            r0 = (r13 > r11 ? 1 : (r13 == r11 ? 0 : -1));
            if (r0 <= 0) goto L_0x016f;
        L_0x014f:
            r0 = "install_time";
            r13 = r13 - r11;
            r7.put(r0, r13);	 Catch:{ all -> 0x0166 }
            r0 = "install_again";
            r11 = r2.v;	 Catch:{ all -> 0x0166 }
            r13 = r1.c;	 Catch:{ all -> 0x0166 }
            r8 = (r11 > r13 ? 1 : (r11 == r13 ? 0 : -1));
            if (r8 <= 0) goto L_0x0161;
        L_0x015f:
            r8 = 1;
            goto L_0x0162;
        L_0x0161:
            r8 = 0;
        L_0x0162:
            r7.put(r0, r8);	 Catch:{ all -> 0x0166 }
            goto L_0x0167;
        L_0x0167:
            if (r4 != 0) goto L_0x016c;
        L_0x0169:
            r0 = 2003; // 0x7d3 float:2.807E-42 double:9.896E-321;
            goto L_0x0171;
        L_0x016c:
            r0 = 2004; // 0x7d4 float:2.808E-42 double:9.9E-321;
            goto L_0x0171;
        L_0x016f:
            r0 = 2000; // 0x7d0 float:2.803E-42 double:9.88E-321;
        L_0x0171:
            r1.d = r0;
            r8 = "fail_status";
            r0 = java.lang.Integer.valueOf(r0);	 Catch:{ Exception -> 0x01dd }
            r7.putOpt(r8, r0);	 Catch:{ Exception -> 0x01dd }
            r0 = "available_space";
            r11 = 1048576; // 0x100000 float:1.469368E-39 double:5.180654E-318;
            r13 = r5 / r11;
            r8 = java.lang.Long.valueOf(r13);	 Catch:{ Exception -> 0x01dd }
            r7.putOpt(r0, r8);	 Catch:{ Exception -> 0x01dd }
            r0 = "total_space";
            r9 = r9 / r11;
            r8 = java.lang.Long.valueOf(r9);	 Catch:{ Exception -> 0x01dd }
            r7.putOpt(r0, r8);	 Catch:{ Exception -> 0x01dd }
            r8 = 0;
            r0 = (r18 > r8 ? 1 : (r18 == r8 ? 0 : -1));
            if (r0 <= 0) goto L_0x01a5;
        L_0x019a:
            r10 = "package_size";
            r13 = r18 / r11;
            r11 = java.lang.Long.valueOf(r13);	 Catch:{ Exception -> 0x01dd }
            r7.putOpt(r10, r11);	 Catch:{ Exception -> 0x01dd }
        L_0x01a5:
            r10 = "space_enough";
            r13 = 2;
            if (r3 == 0) goto L_0x01ac;
        L_0x01aa:
            r3 = 1;
            goto L_0x01ad;
        L_0x01ac:
            r3 = 2;
        L_0x01ad:
            r3 = java.lang.Integer.valueOf(r3);	 Catch:{ Exception -> 0x01dd }
            r7.putOpt(r10, r3);	 Catch:{ Exception -> 0x01dd }
            r3 = (r5 > r8 ? 1 : (r5 == r8 ? 0 : -1));
            if (r3 <= 0) goto L_0x01c4;
        L_0x01b8:
            if (r0 <= 0) goto L_0x01c4;
        L_0x01ba:
            r0 = "available_space_ratio";
            r5 = (double) r5;	 Catch:{ Exception -> 0x01dd }
            r8 = r18;
            r8 = (double) r8;	 Catch:{ Exception -> 0x01dd }
            r5 = r5 / r8;
            r7.put(r0, r5);	 Catch:{ Exception -> 0x01dd }
        L_0x01c4:
            r0 = "permission_unknown_source_install";
            if (r4 == 0) goto L_0x01ca;
        L_0x01c8:
            r3 = 1;
            goto L_0x01cb;
        L_0x01ca:
            r3 = 2;
        L_0x01cb:
            r3 = java.lang.Integer.valueOf(r3);	 Catch:{ Exception -> 0x01dd }
            r7.putOpt(r0, r3);	 Catch:{ Exception -> 0x01dd }
            r0 = "is_update_download";
            r3 = r2.A;	 Catch:{ Exception -> 0x01dd }
            if (r3 == 0) goto L_0x01d9;
        L_0x01d8:
            r13 = 1;
        L_0x01d9:
            r7.put(r0, r13);	 Catch:{ Exception -> 0x01dd }
            goto L_0x01e1;
        L_0x01dd:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x01e1:
            r0 = c.j.a.c.o.b.b.a;
            r3 = "install_failed";
            r0.n(r3, r7, r2);
            r2 = 1;
            return r2;
        L_0x01ea:
            r2 = 0;
            return r2;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g$b.a():boolean");
        }

        public void run() {
            try {
                if (a()) {
                    g d = g.d();
                    long j = this.a;
                    int i = this.b;
                    Objects.requireNonNull(d);
                    long c = c.j.a.d.b.l.a.d(i).c("check_install_finish_hijack_delay_time", 900000);
                    if (c >= 0) {
                        c.j.a.c.o.a.a.a(new e(d, j), Math.max(c, 300000));
                    }
                }
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    /* compiled from: AdDownloadCompletedEventHandlerImpl */
    public class c implements Runnable {
        public final c.j.a.b.a.c.a a;

        public c(c.j.a.b.a.c.a aVar) {
            this.a = aVar;
        }

        public void run() {
            try {
                c.j.a.b.a.c.a aVar = this.a;
                aVar.M = true;
                g gVar = g.this;
                Objects.requireNonNull(gVar);
                SystemClock.sleep(20000);
                int i = 15;
                while (i > 0) {
                    if (d.o(aVar)) {
                        gVar.m(aVar.e);
                        break;
                    }
                    i--;
                    if (i == 0) {
                        break;
                    }
                    SystemClock.sleep(20000);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } catch (Throwable th) {
                this.a.M = false;
            }
            this.a.M = false;
        }
    }

    /* compiled from: AdDownloadSecurityManager */
    public class f implements Runnable {
        public final /* synthetic */ String a;

        public f(h hVar, String str) {
            this.a = str;
        }

        public void run() {
            y.q().a(3, y.a(), null, "下载失败，请重试！", null, 0);
            s a = x.b().a(this.a);
            if (a != null && a.e.size() != 0) {
                Iterator it = ((ArrayList) x.a(a.e)).iterator();
                while (it.hasNext()) {
                    ((c.j.a.a.a.c.e) it.next()).a();
                }
                com.ss.android.socialbase.downloader.g.c cVar = a.g;
                if (cVar != null) {
                    cVar.b0(-4);
                }
            }
        }
    }

    /* compiled from: AdDownloadSecurityManager */
    public class h {
        public static volatile h b;
        public Handler a = null;

        public static h a() {
            if (b == null) {
                synchronized (h.class) {
                    if (b == null) {
                        b = new h();
                    }
                }
            }
            return b;
        }
    }

    /* compiled from: ChunkCalculatorFactory */
    public /* synthetic */ class k {
        public static final /* synthetic */ int[] a;

        /* JADX WARNING: Missing exception handler attribute for start block: B:15:0x001b */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Can't wrap try/catch for region: R(13:0|(2:1|2)|3|5|6|7|(2:9|10)|11|13|14|15|16|18) */
        /* JADX WARNING: Missing block: B:19:?, code skipped:
            return;
     */
        static {
            /*
            c.j.a.d.b.i.l.values();
            r0 = 5;
            r1 = new int[r0];
            a = r1;
            r2 = 0;
            r3 = 1;
            r1[r2] = r3;	 Catch:{ NoSuchFieldError -> 0x000c }
        L_0x000c:
            r1 = 2;
            r2 = a;	 Catch:{ NoSuchFieldError -> 0x0011 }
            r2[r3] = r1;	 Catch:{ NoSuchFieldError -> 0x0011 }
        L_0x0011:
            r2 = 3;
            r3 = a;	 Catch:{ NoSuchFieldError -> 0x0016 }
            r3[r1] = r2;	 Catch:{ NoSuchFieldError -> 0x0016 }
        L_0x0016:
            r1 = 4;
            r3 = a;	 Catch:{ NoSuchFieldError -> 0x001b }
            r3[r2] = r1;	 Catch:{ NoSuchFieldError -> 0x001b }
        L_0x001b:
            r2 = a;	 Catch:{ NoSuchFieldError -> 0x001f }
            r2[r1] = r0;	 Catch:{ NoSuchFieldError -> 0x001f }
        L_0x001f:
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g$k.m2284clinit():void");
        }
    }

    /* compiled from: CleanSpaceHelper */
    public class p {
        public Handler a;
        public c.j.a.c.g$g.d.b b;
        public AtomicBoolean c = new AtomicBoolean(false);
        public AtomicBoolean d = new AtomicBoolean(false);

        /* compiled from: CleanSpaceHelper */
        public class b implements Runnable {
            public final /* synthetic */ c.j.a.b.a.c.a a;
            public final /* synthetic */ d b;

            public b(c.j.a.b.a.c.a aVar, d dVar) {
                this.a = aVar;
                this.b = dVar;
            }

            public void run() {
                if (!p.this.c.get()) {
                    p.this.c.set(true);
                    c.j.a.c.o.b.b.a.i("clean_fetch_apk_head_failed", this.a);
                    this.b.a();
                }
            }
        }

        /* compiled from: CleanSpaceHelper */
        public class c {
            public c(p pVar, c.j.a.b.a.c.a aVar, d dVar, String str) {
            }
        }

        /* compiled from: CleanSpaceHelper */
        public class d implements Runnable {
            public final /* synthetic */ d a;

            public d(p pVar, d dVar) {
                this.a = dVar;
            }

            public void run() {
                this.a.a();
            }
        }

        /* compiled from: CleanSpaceHelper */
        public class a implements e {
            public final /* synthetic */ int a;
            public final /* synthetic */ String b;
            public final /* synthetic */ c.j.a.b.a.c.a c;
            public final /* synthetic */ long d;
            public final /* synthetic */ d e;

            public a(int i, String str, c.j.a.b.a.c.a aVar, long j, d dVar) {
                this.a = i;
                this.b = str;
                this.c = aVar;
                this.d = j;
                this.e = dVar;
            }
        }

        public p(Handler handler) {
            this.a = handler;
        }

        public void a(int i, long j, long j2, d dVar) {
            c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
            boolean z = false;
            this.d.set(false);
            long c = c.j.a.d.b.l.a.d(i).c("clean_fetch_apk_head_time_out", 800);
            this.c.set(false);
            String a = this.b.b.a();
            c.j.a.c.g$g.d dVar2 = c.j.a.c.g$g.d.c.a;
            Objects.requireNonNull(dVar2);
            c.j.a.b.a.c.a aVar = null;
            if (!TextUtils.isEmpty(a)) {
                for (c.j.a.b.a.c.a aVar2 : dVar2.e.values()) {
                    if (aVar2 != null && a.equals(aVar2.f)) {
                        aVar = aVar2;
                        break;
                    }
                }
            }
            if (aVar == null) {
                c.j.a.c.g$g.d.b bVar2 = this.b;
                aVar = new c.j.a.b.a.c.a(bVar2.b, bVar2.c, bVar2.d, 0);
                c.j.a.c.g$g.d.c.a.e(aVar);
            }
            c.j.a.b.a.c.a aVar3 = aVar;
            aVar3.I = false;
            c.j.a.c.g$i.c a2 = c.j.a.c.g$i.c.a();
            String str = aVar3.f;
            Objects.requireNonNull(a2);
            if (!TextUtils.isEmpty(str)) {
                a2.b.remove(str);
            }
            if ((c.j.a.d.b.l.a.d(i).c("clean_fetch_apk_switch", 0) == 1 ? 1 : null) != null && y.v(i)) {
                z = true;
            }
            if (j2 > 0 && y.v(i)) {
                bVar.i("clean_no_need_fetch_apk_size", aVar3);
                b(i, a, j2, aVar3, j, dVar);
            } else if (z) {
                bVar.i("clean_fetch_apk_head_switch_open", aVar3);
                c.j.a.d.b.i.a.b.b.post(new c.j.a.d.b.i.a.c(a, new q(this, aVar3, new a(i, a, aVar3, j, dVar))));
            } else {
                bVar.i("clean_fetch_apk_head_switch_close", aVar3);
                c = 0;
            }
            this.a.postDelayed(new b(aVar3, dVar), c);
        }

        public final void b(int i, String str, long j, c.j.a.b.a.c.a aVar, long j2, d dVar) {
            long j3 = j;
            c.j.a.b.a.c.a aVar2 = aVar;
            d dVar2 = dVar;
            String str2 = "quite_clean_size";
            c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
            boolean z = true;
            this.c.set(true);
            if (j3 > 0) {
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.putOpt("apk_size", Long.valueOf(j));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                j3 = (Double.valueOf((c.j.a.d.b.l.a.d(i).a("clean_min_install_size", 0.0d) + 1.0d) * ((double) j3)).longValue() + c.j.a.d.b.l.a.d(i).c("storage_min_size", 0)) - j2;
                aVar2.I = true;
                long c = c();
                if (c < j3) {
                    try {
                        jSONObject.putOpt("available_space", Long.valueOf(c));
                        jSONObject.putOpt("apk_download_need_size", Long.valueOf(j3));
                    } catch (JSONException e2) {
                        e2.printStackTrace();
                    }
                    bVar.n("clean_space_no_enough_for_download", jSONObject, aVar2);
                    long c2 = c();
                    c.h.a.m0.r.a.g();
                    c.h.a.m0.r.a.q();
                    if ((c.j.a.d.b.l.a.d(aVar2.q).b("clean_app_cache_dir", 0) == 1 ? 1 : null) != null) {
                        c.h.a.m0.r.a.h(y.a());
                    }
                    long c3 = c();
                    JSONObject jSONObject2 = new JSONObject();
                    try {
                        jSONObject2.putOpt(str2, Long.valueOf(c3 - c2));
                    } catch (JSONException e22) {
                        e22.printStackTrace();
                    }
                    bVar.n("clean_quite_finish", jSONObject2, aVar2);
                    c2 = c();
                    if ((c2 < j3 ? 1 : null) != null) {
                        String str3 = aVar2.f;
                        c.j.a.c.g$i.c a = c.j.a.c.g$i.c.a();
                        c cVar = new c(this, aVar2, dVar2, str3);
                        Objects.requireNonNull(a);
                        if (!TextUtils.isEmpty(str3)) {
                            a.b.put(str3, cVar);
                        }
                        if (c.j.a.d.b.l.a.d(i).b("exec_clear_space_switch", 0) != 1) {
                            z = false;
                        }
                        if (z) {
                            bVar.i("cleanspace_switch_open", aVar2);
                            JSONObject jSONObject3 = new JSONObject();
                            try {
                                jSONObject3.putOpt("show_dialog_result", Integer.valueOf(3));
                            } catch (JSONException e222) {
                                e222.printStackTrace();
                            }
                            bVar.n("cleanspace_window_show", jSONObject3, aVar2);
                        } else {
                            bVar.i("clean_space_switch_closed", aVar2);
                        }
                    } else {
                        aVar2.H = "1";
                        c.j.a.c.g$g.g.b.a.a(aVar2);
                        try {
                            jSONObject.putOpt(str2, Long.valueOf(c2 - c));
                        } catch (JSONException e2222) {
                            e2222.printStackTrace();
                        }
                        bVar.n("cleanspace_download_after_quite_clean", jSONObject, aVar2);
                    }
                }
            }
            this.a.post(new d(this, dVar2));
        }

        public final long c() {
            try {
                return c.j.a.d.b.n.a.J(Environment.getExternalStorageDirectory().toString());
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }
        }
    }

    /* compiled from: CommonDownloadHandler */
    public class r implements Runnable {
        public final /* synthetic */ s a;

        public r(s sVar) {
            this.a = sVar;
        }

        public void run() {
            Iterator it = ((ArrayList) x.a(this.a.e)).iterator();
            while (it.hasNext()) {
                ((c.j.a.a.a.c.e) it.next()).b(s.h(this.a));
            }
        }
    }

    /* compiled from: DownloadHandler */
    public interface t {
        t a(c.j.a.a.a.c.c cVar);

        void a();

        void a(long j, int i);

        void a(boolean z);

        boolean a(int i);

        t b(Context context);

        boolean b();

        t c(int i, c.j.a.a.a.c.e eVar);

        long d();

        t d(c.j.a.a.a.a.j jVar);

        t e(c.j.a.a.a.c.d dVar);

        t f(c.j.a.a.a.c.b bVar);

        void g();
    }

    /* compiled from: GlobalInfo */
    public class y {
        public static Context a;
        public static c.j.a.a.a.a.c b;
        public static c.j.a.a.a.a.b c;
        public static c.j.a.a.a.a.g d;
        public static c.j.a.a.a.a.d e;
        public static c.j.a.a.a.a.e f;
        public static c.j.a.a.a.a.f g;
        public static c.j.a.a.a.e.a h;
        public static com.bytedance.sdk.openadsdk.downloadnew.a.a.a i;
        public static c.j.a.d.a.h.d j;
        public static c.j.a.a.a.d.a k;
        public static c.j.a.c.g$d.d l;

        /* compiled from: GlobalInfo */
        public static class a implements c.j.a.a.a.a.b {
        }

        /* compiled from: GlobalInfo */
        public static class b implements c.j.a.d.a.h.d {
            public void a(com.ss.android.socialbase.downloader.g.c cVar, com.ss.android.socialbase.downloader.e.a aVar, int i) {
            }
        }

        /* compiled from: GlobalInfo */
        public static class c implements c.j.a.a.a.a.f {
            public JSONObject a() {
                return new JSONObject();
            }
        }

        /* compiled from: GlobalInfo */
        public static class d implements c.j.a.a.a.d.a {
            public c.j.a.c.y.a.g a = null;
        }

        public static Context a() {
            Context context = a;
            if (context != null) {
                return context;
            }
            throw new IllegalArgumentException("Context is null");
        }

        public static c.j.a.c.g$g.e b(Context context, String str) {
            if (context == null || TextUtils.isEmpty(str)) {
                return new c.j.a.c.g$g.e(6, 11);
            }
            Uri parse;
            c.j.a.c.g$g.e eVar;
            String str2 = "SAMSUNG";
            if (d0.b(str2)) {
                String str3 = "com.sec.android.app.samsungapps";
                if (c.j.a.c.q.d.p(context, str3)) {
                    try {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append("http://www.samsungapps.com/appquery/appDetail.as?appId=");
                        stringBuilder.append(str);
                        parse = Uri.parse(stringBuilder.toString());
                        Intent intent = new Intent();
                        intent.setClassName(str3, "com.sec.android.app.samsungapps.Main");
                        intent.setData(parse);
                        context.startActivity(intent);
                        eVar = new c.j.a.c.g$g.e(5);
                    } catch (Exception unused) {
                        eVar = new c.j.a.c.g$g.e(6, 14);
                    }
                    return eVar;
                }
            }
            StringBuilder stringBuilder2 = new StringBuilder();
            stringBuilder2.append("market://details?id=");
            stringBuilder2.append(str);
            parse = Uri.parse(stringBuilder2.toString());
            if (parse != null) {
                if ("market".equals(parse.getScheme())) {
                    try {
                        Intent intent2 = new Intent(ACTION.HWID_SCHEME_URL, parse);
                        Object obj = null;
                        try {
                            List queryIntentActivities = context.getPackageManager().queryIntentActivities(intent2, 65536);
                            if (!(queryIntentActivities == null || queryIntentActivities.isEmpty())) {
                                obj = 1;
                            }
                        } catch (Exception unused2) {
                        }
                        if (obj == null) {
                            eVar = new c.j.a.c.g$g.e(6, 13);
                        } else {
                            if (d0.f == null) {
                                d0.b("");
                            }
                            str = d0.f;
                            if (c.j.a.c.q.d.p(context, str) && !d0.b(str2)) {
                                intent2.setPackage(str);
                            }
                            if (!(context instanceof Activity)) {
                                intent2.addFlags(268435456);
                            }
                            context.startActivity(intent2);
                            eVar = new c.j.a.c.g$g.e(5);
                        }
                    } catch (Exception unused3) {
                        eVar = new c.j.a.c.g$g.e(6, 14);
                    }
                    return eVar;
                }
            }
            eVar = new c.j.a.c.g$g.e(6, 12);
            return eVar;
        }

        public static String c(String str) {
            if (TextUtils.isEmpty(str)) {
                return null;
            }
            File file = new File(str);
            try {
                if (file.exists()) {
                    str = c.j.a.e.b.a(file, 9, 8192);
                    return str;
                }
                str = "";
                return str;
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }

        public static JSONObject d(String str) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.putOpt("open_url", str);
            } catch (Exception unused) {
            }
            return jSONObject;
        }

        public static void e(c.j.a.b.a.c.a aVar, JSONObject jSONObject) {
            try {
                jSONObject.put("is_patch_apply_handled", aVar.C ? 1 : 0);
                jSONObject.put("origin_mime_type", aVar.B);
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }

        public static void f(JSONObject jSONObject, int i) {
            if (jSONObject != null) {
                c.j.a.d.b.l.a d = c.j.a.d.b.l.a.d(i);
                JSONObject l = d.l("anti_hijack_report_config");
                if (l != null) {
                    try {
                        c.j.a.d.a.m a = c.j.a.d.a.g.a(l.optString("report_installer_pkg_name"));
                        if (a != null) {
                            jSONObject.put("installer_package_name", a.a);
                            jSONObject.put("installer_version_code", a.f);
                            jSONObject.put("installer_version_name", a.e);
                        }
                        a = c.j.a.d.a.g.a(l.optString("report_file_manager_pkg_name"));
                        if (a != null) {
                            jSONObject.put("file_manager_package_name", a.a);
                            jSONObject.put("file_manager_version_code", a.f);
                            jSONObject.put("file_manager_version_name", a.e);
                        }
                        c.j.a.d.a.m a2 = c.j.a.d.a.g.a(l.optString("report_appstore_pkg_name"));
                        if (a2 != null) {
                            jSONObject.put("appstore_package_name", a2.a);
                            jSONObject.put("appstore_version_code", a2.f);
                            jSONObject.put("appstore_version_name", a2.e);
                        }
                        jSONObject.put("rom_version", d0.h());
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                }
                int i2 = 0;
                if (d.b("report_unknown_source", 0) == 1) {
                    try {
                        String str = "is_unknown_source_enabled";
                        if (c.j.a.d.a.g.e(c.j.a.d.b.e.b.a())) {
                            i2 = 1;
                        }
                        jSONObject.put(str, i2);
                    } catch (Throwable unused) {
                    }
                }
            }
        }

        public static void g(Object[] objArr) {
            int i = 0;
            if (t().optInt("hook", 0) == 1 && (objArr[1] instanceof String) && (objArr[2] instanceof Intent)) {
                Intent intent = (Intent) objArr[2];
                if (ACTION.HWID_SCHEME_URL.equals(intent.getAction()) && c.j.a.d.b.b.e.a.equals(intent.getType())) {
                    String str = "null";
                    String str2;
                    if (d0.e()) {
                        String optString = t().optString("hook_vivo_arg", "com.android.settings");
                        if (!str.equals(optString)) {
                            objArr[1] = optString;
                        }
                    } else if (d0.f()) {
                        JSONObject t = t();
                        StringBuilder g = c.b.a.a.a.g("com.");
                        g.append(c.j.a.d.b.b.e.c);
                        g.append(".market");
                        String optString2 = t.optString("hook_kllk_arg1", g.toString());
                        if (!str.equals(optString2)) {
                            objArr[1] = optString2;
                        }
                        String optString3 = t().optString("hook_kllk_arg2", "com.android.browser");
                        t = t();
                        StringBuilder g2 = c.b.a.a.a.g("m.store.");
                        g2.append(c.j.a.d.b.b.e.c);
                        g2.append("mobile.com");
                        optString2 = t.optString("hook_kllk_arg3", g2.toString());
                        g2 = new StringBuilder();
                        g2.append(c.j.a.d.b.b.e.c);
                        str2 = "_extra_pkg_name";
                        g2.append(str2);
                        intent.putExtra(g2.toString(), optString3);
                        str = "refererHost";
                        intent.putExtra(str, optString2);
                        if (t().optInt("hook_kllk_arg4", 0) == 1) {
                            i = 1;
                        }
                        if (i != 0) {
                            Intent intent2 = new Intent();
                            StringBuilder stringBuilder = new StringBuilder();
                            stringBuilder.append(c.j.a.d.b.b.e.c);
                            stringBuilder.append(str2);
                            intent2.putExtra(stringBuilder.toString(), optString3);
                            intent2.putExtra(str, optString2);
                            intent.putExtra("android.intent.extra.INTENT", intent2);
                        }
                    } else if (d0.a()) {
                        str2 = "com.huawei.appmarket";
                        String optString4 = t().optString("hook_huawei_arg1", str2);
                        if (!str.equals(optString4)) {
                            objArr[1] = optString4;
                        }
                        intent.putExtra("caller_package", t().optString("hook_huawei_arg2", str2));
                    }
                }
            }
        }

        public static boolean h(int i) {
            return i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 7 || i == 8;
        }

        public static boolean i(Uri uri) {
            if (uri == null) {
                return false;
            }
            String scheme = uri.getScheme();
            if (TextUtils.isEmpty(scheme)) {
                return false;
            }
            if ("market".equals(scheme) || "appmarket".equals(scheme) || "oaps".equals(scheme) || "oppomarket".equals(scheme) || "mimarket".equals(scheme) || "vivomarket".equals(scheme) || "vivoMarket".equals(scheme) || "gomarket".equals(scheme) || "goMarket".equals(scheme) || "mstore".equals(scheme) || "samsungapps".equals(scheme)) {
                return true;
            }
            return false;
        }

        public static boolean j(c.j.a.c.g$g.d.b bVar) {
            String str;
            c.j.a.c.o.b bVar2 = c.j.a.c.o.b.b.a;
            c.j.a.a.a.e.b x = bVar.b.x();
            if (x == null) {
                str = null;
            } else {
                str = x.a;
            }
            c.j.a.c.g$g.e m = m(str);
            if (m.a == 2) {
                if (!TextUtils.isEmpty(str)) {
                    bVar2.o("deeplink_url_open_fail", d(str), bVar);
                }
                m = l(a(), bVar.b.v());
            }
            if ((((c.j.a.b.a.c.a) c.j.a.c.g$g.d.c.a.e.get(Long.valueOf(bVar.a))) == null ? 1 : null) != null && t().optInt("link_ad_click_event", 1) == 1) {
                bVar2.c(bVar.a, 0);
            }
            int i = m.a;
            c.j.a.a.a.a.b p;
            if (i == 1) {
                bVar2.j("deeplink_url_open", bVar);
                p = p();
                a();
                bVar.b.v();
                Objects.requireNonNull((a) p);
                return true;
            } else if (i == 3) {
                bVar2.j("deeplink_app_open", bVar);
                p = p();
                a();
                bVar.b.v();
                Objects.requireNonNull((a) p);
                return true;
            } else if (i != 4) {
                c.j.a.c.q.d.n();
                return false;
            } else {
                bVar2.j("deeplink_app_open_fail", bVar);
                return false;
            }
        }

        public static boolean k(String str, c.j.a.b.a.c.a aVar) {
            c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
            int i = aVar.i;
            Object obj = (i == 2 || i == 1) ? 1 : null;
            if (obj == null || TextUtils.isEmpty(aVar.g)) {
                return false;
            }
            c.j.a.d.b.o.d.a().e(aVar.q);
            bVar.i("deeplink_url_app", aVar);
            i = m(aVar.g).a;
            if (i == 1 || i == 3) {
                bVar.i("deeplink_open_success", aVar);
                c.j.a.a.a.a.b p = p();
                a();
                aVar.a();
                Objects.requireNonNull((a) p);
                return true;
            }
            bVar.i("deeplink_open_fail", aVar);
            return false;
        }

        public static c.j.a.c.g$g.e l(Context context, String str) {
            Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(str);
            if (launchIntentForPackage == null) {
                launchIntentForPackage = null;
            } else {
                String str2 = "android.intent.category.LAUNCHER";
                if (!launchIntentForPackage.hasCategory(str2)) {
                    launchIntentForPackage.addCategory(str2);
                }
                launchIntentForPackage.setPackage(null);
                launchIntentForPackage.addFlags(2097152);
                launchIntentForPackage.addFlags(268435456);
            }
            if (launchIntentForPackage == null) {
                return new c.j.a.c.g$g.e(4);
            }
            launchIntentForPackage.putExtra("START_ONLY_FOR_ANDROID", true);
            try {
                context.startActivity(launchIntentForPackage);
                return new c.j.a.c.g$g.e(3);
            } catch (Exception unused) {
                return new c.j.a.c.g$g.e(4);
            }
        }

        public static c.j.a.c.g$g.e m(String str) {
            int i = VERSION.SDK_INT;
            if (TextUtils.isEmpty(str)) {
                return new c.j.a.c.g$g.e(2, 21);
            }
            Context a = a();
            Uri parse = Uri.parse(str);
            Intent intent = new Intent(ACTION.HWID_SCHEME_URL);
            intent.setData(parse);
            intent.addFlags(268435456);
            Object obj = null;
            if (a == null) {
                a = a();
            }
            List queryIntentActivities = a.getPackageManager().queryIntentActivities(intent, 65536);
            if (queryIntentActivities != null && queryIntentActivities.size() > 0) {
                obj = 1;
            }
            if (obj == null) {
                return new c.j.a.c.g$g.e(2);
            }
            String str2 = "open_url_mode";
            if (t().optInt(str2) == 0) {
                com.bytedance.sdk.openadsdk.downloadnew.a.a.a aVar = i;
                if (aVar != null && aVar.a() && i < 29) {
                    TTDelegateActivity.b(str);
                    return new c.j.a.c.g$g.e(1);
                }
            }
            if (t().optInt(str2) != 1 || i < 26 || i >= 29) {
                intent.putExtra("open_url", str);
                intent.addFlags(268435456);
                try {
                    a().startActivity(intent);
                    return new c.j.a.c.g$g.e(1);
                } catch (Exception unused) {
                    return new c.j.a.c.g$g.e(2);
                }
            }
            TTDelegateActivity.b(str);
            return new c.j.a.c.g$g.e(1);
        }

        public static JSONObject n(c.j.a.a.a.c.d dVar) {
            if (dVar == null) {
                return null;
            }
            if (dVar.t()) {
                return t().optJSONObject("ad");
            }
            return dVar.p();
        }

        public static void o(Context context) {
            if (a == null && context != null && context.getApplicationContext() != null) {
                a = context.getApplicationContext();
            }
        }

        public static c.j.a.a.a.a.b p() {
            if (c == null) {
                c = new a();
            }
            return c;
        }

        public static c.j.a.a.a.a.g q() {
            if (d == null) {
                d = new c.j.a.c.k.d();
            }
            return d;
        }

        public static c.j.a.a.a.a.e r() {
            if (f == null) {
                f = new c.j.a.c.k.e();
            }
            return f;
        }

        public static c.j.a.d.a.h.d s() {
            if (j == null) {
                j = new b();
            }
            return j;
        }

        public static JSONObject t() {
            if (g == null) {
                g = new c();
            }
            return (JSONObject) c.j.a.c.q.d.e(g.a(), new JSONObject());
        }

        public static c.j.a.a.a.d.a u() {
            if (k == null) {
                k = new d();
            }
            return k;
        }

        public static boolean v(int i) {
            return c.j.a.d.b.l.a.d(i).c("clean_space_optimise_switch", 0) == 1;
        }
    }

    /* compiled from: AdDelayTaskManager */
    public class e implements c.j.a.c.q.e.a {
        public static e c;
        public c.j.a.c.q.e a = new c.j.a.c.q.e(Looper.getMainLooper(), this);
        public long b;

        public void a(Message message) {
            if (message.what == AGCServerException.OK) {
                c.j.a.c.g$g.a aVar = (c.j.a.c.g$g.a) message.obj;
                int i = message.arg1;
                c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
                com.bytedance.sdk.openadsdk.downloadnew.a.a.a aVar2 = y.i;
                if (aVar2 != null && !aVar2.a() && aVar != null) {
                    if (2 == i) {
                        c.j.a.b.a.c.a g = c.j.a.c.g$g.d.c.a.g(aVar.b);
                        JSONObject jSONObject = new JSONObject();
                        int i2 = -1;
                        try {
                            jSONObject.put("ttdownloader_type", "miui_silent_install");
                            String str = "ttdownloader_message";
                            if (d.p(y.a(), aVar.d)) {
                                jSONObject.put(str, "miui_silent_install_succeed");
                                i2 = 4;
                            } else {
                                jSONObject.put(str, "miui_silent_install_failed: has started service");
                                i2 = 5;
                            }
                        } catch (Exception unused) {
                        }
                        y.s().a(null, new com.ss.android.socialbase.downloader.e.a(i2, jSONObject.toString()), i2);
                        bVar.q("embeded_ad", "anti_hijack_result", jSONObject, g);
                    }
                    if (d.p(y.a(), aVar.d)) {
                        bVar.g("delayinstall_installed", aVar.b);
                    } else if (d.m(aVar.g)) {
                        c.j.a.c.g$d.b a = c.j.a.c.g$d.b.a();
                        if (TextUtils.equals(a.c, aVar.d)) {
                            bVar.g("delayinstall_conflict_with_back_dialog", aVar.b);
                            return;
                        }
                        bVar.g("delayinstall_install_start", aVar.b);
                        Context a2 = y.a();
                        int i3 = (int) aVar.a;
                        String str2 = i.j;
                        c.j.a.d.a.h.c(a2, i3, true);
                    } else {
                        bVar.g("delayinstall_file_lost", aVar.b);
                    }
                }
            }
        }
    }

    /* compiled from: AdQuickAppManager */
    public class j implements c.j.a.c.q.e.a {
        public static final /* synthetic */ int a = 0;
    }

    /* compiled from: ChunkCalculatorFactory */
    public class l implements c.j.a.d.b.e.l {
        public final String a;
        public m b;

        public l(m mVar, String str) {
            this.b = mVar;
            this.a = str;
        }

        public int a(long j) {
            String str = this.a;
            Object obj = null;
            if (!TextUtils.isEmpty(str) && (str.startsWith("http://ad.toutiao.com/advertiser_package/") || str.startsWith("https://ad.toutiao.com/advertiser_package/") || (!TextUtils.isEmpty(str) && (str.startsWith("http://lf3-ttcdn-tos.pstatp.com/") || str.startsWith("https://lf3-ttcdn-tos.pstatp.com/"))))) {
                obj = 1;
            }
            if (obj != null) {
                m mVar = this.b;
                if (mVar != null) {
                    return mVar.a(j);
                }
            }
            return 1;
        }
    }

    /* compiled from: ChunkCalculatorFactory */
    public class m implements c.j.a.d.b.e.l {
        public int a;
        public ArrayList<int[]> b = new ArrayList();

        public m(JSONObject jSONObject) {
            this.a = jSONObject.optInt("is_open_exp", 0);
            String str = "download_chunk_config";
            if (jSONObject.has(str)) {
                String obj = jSONObject.opt(str).toString();
                if (!TextUtils.isEmpty(obj)) {
                    JSONObject jSONObject2 = null;
                    try {
                        jSONObject2 = new JSONObject(obj);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (jSONObject2 != null) {
                        r2 = new String[5];
                        String[][] strArr = new String[5][];
                        r2[1] = jSONObject2.optString("download_chunk_1");
                        r2[2] = jSONObject2.optString("download_chunk_2");
                        r2[3] = jSONObject2.optString("download_chunk_3");
                        r2[4] = jSONObject2.optString("download_chunk_4");
                        for (int i = 1; i < 5; i++) {
                            if (!TextUtils.isEmpty(r2[i])) {
                                try {
                                    strArr[i] = r2[i].split(",");
                                } catch (Throwable th) {
                                    th.printStackTrace();
                                }
                                for (int i2 = 0; i2 < strArr[i].length - 1; i2 += 2) {
                                    try {
                                        int parseInt = Integer.parseInt(strArr[i][i2]);
                                        int parseInt2 = Integer.parseInt(strArr[i][i2 + 1]);
                                        this.b.add(new int[]{i, parseInt, parseInt2});
                                    } catch (Throwable th2) {
                                        th2.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        public int a(long j) {
            int i = this.a;
            Object obj = (i == 1 || i == 3) ? 1 : null;
            if (obj == null) {
                return 1;
            }
            int i2 = (int) (j / 1048576);
            for (int i3 = 0; i3 < this.b.size(); i3++) {
                int[] iArr = (int[]) this.b.get(i3);
                if (i2 >= iArr[1] && i2 < iArr[2]) {
                    return iArr[0];
                }
            }
            return 1;
        }
    }

    /* compiled from: ChunkCalculatorFactory */
    public class n implements c.j.a.d.b.e.k {
        public int a;
        public ArrayList<int[]> b = new ArrayList();

        public n(JSONObject jSONObject) {
            this.a = jSONObject.optInt("is_open_exp", 0);
            String str = ",";
            String str2 = "download_chunk_config";
            if (jSONObject.has(str2)) {
                String obj = jSONObject.opt(str2).toString();
                if (!TextUtils.isEmpty(obj)) {
                    JSONObject jSONObject2 = null;
                    try {
                        jSONObject2 = new JSONObject(obj);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (jSONObject2 != null) {
                        obj = jSONObject2.optString("network_quality_operation");
                        str2 = jSONObject2.optString("network_quality_operand");
                        if (!TextUtils.isEmpty(obj) && !TextUtils.isEmpty(str2)) {
                            try {
                                String[] split = obj.split(str);
                                String[] split2 = str2.split(str);
                                if (split.length < 5) {
                                    return;
                                }
                                if (split2.length >= 5) {
                                    for (int i = 0; i < 5; i++) {
                                        int parseInt = Integer.parseInt(split[i]);
                                        int parseInt2 = Integer.parseInt(split2[i]);
                                        this.b.add(new int[]{parseInt, parseInt2});
                                    }
                                }
                            } catch (Throwable unused) {
                            }
                        }
                    }
                }
            }
        }

        public int a(int i, c.j.a.d.b.i.l lVar) {
            int i2 = this.a;
            Object obj = (i2 == 2 || i2 == 3) ? 1 : null;
            if (obj == null || this.b.size() < 5) {
                return i;
            }
            int[] iArr = null;
            int i3 = k.a[lVar.ordinal()];
            if (i3 == 1) {
                iArr = (int[]) this.b.get(0);
            } else if (i3 == 2) {
                iArr = (int[]) this.b.get(1);
            } else if (i3 == 3) {
                iArr = (int[]) this.b.get(2);
            } else if (i3 == 4) {
                iArr = (int[]) this.b.get(3);
            } else if (i3 == 5) {
                iArr = (int[]) this.b.get(4);
            }
            if (iArr == null || iArr.length < 2) {
                return i;
            }
            i3 = iArr[0];
            if (i3 == 1) {
                i += iArr[1];
            } else if (i3 == 2) {
                i -= iArr[1];
            } else if (i3 == 3) {
                i = iArr[1];
            }
            return i > 1 ? i : 1;
        }
    }

    /* compiled from: CleanSpaceHelper */
    public class q implements c.j.a.d.b.i.j {
        public final /* synthetic */ c.j.a.b.a.c.a a;
        public final /* synthetic */ e b;
        public final /* synthetic */ p c;

        public q(p pVar, c.j.a.b.a.c.a aVar, e eVar) {
            this.c = pVar;
            this.a = aVar;
            this.b = eVar;
        }

        public void a(Map<String, String> map) {
            c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
            if (!this.c.c.get()) {
                long parseLong;
                long j;
                this.c.c.set(true);
                if (map != null) {
                    try {
                        bVar.i("clean_fetch_apk_head_success", this.a);
                        parseLong = Long.parseLong((String) map.get("Content-Length"));
                    } catch (Exception e) {
                        e.printStackTrace();
                        j = 0;
                    }
                } else {
                    bVar.i("clean_fetch_apk_head_failed", this.a);
                    parseLong = 0;
                }
                j = parseLong;
                if (j > 0) {
                    JSONObject jSONObject = new JSONObject();
                    try {
                        jSONObject.putOpt("apk_size", Long.valueOf(j));
                        jSONObject.putOpt("available_space", Long.valueOf(this.c.c()));
                    } catch (JSONException e2) {
                        e2.printStackTrace();
                    }
                    bVar.n("clean_fetch_apk_size_success", jSONObject, this.a);
                }
                a aVar = (a) this.b;
                p.this.b(aVar.a, aVar.b, j, aVar.c, aVar.d, aVar.e);
            }
        }
    }

    /* compiled from: CommonDownloadHandler */
    public class s implements t, c.j.a.c.q.e.a {
        public static final String s = "g$s";
        public final c.j.a.c.q.e a;
        public x b;
        public p c;
        public WeakReference<Context> d;
        public final Map<Integer, Object> e = new ConcurrentHashMap();
        public c.j.a.a.a.e.e f;
        public com.ss.android.socialbase.downloader.g.c g;
        public f h;
        public final c.j.a.d.b.d.b i;
        public boolean j;
        public long k;
        public long l;
        public c.j.a.a.a.c.d m;
        public c.j.a.a.a.c.c n;
        public c.j.a.a.a.c.b o;
        public SoftReference<c.j.a.a.a.a.j> p;
        public boolean q;
        public final boolean r;

        /* compiled from: CommonDownloadHandler */
        public interface d {
            void a();
        }

        /* compiled from: CommonDownloadHandler */
        public interface e {
        }

        /* compiled from: CommonDownloadHandler */
        public class f extends AsyncTask<String, Void, com.ss.android.socialbase.downloader.g.c> {
            public f(r rVar) {
            }

            public Object doInBackground(Object[] objArr) {
                String[] strArr = (String[]) objArr;
                Object obj = null;
                if (strArr == null) {
                    return null;
                }
                if (strArr.length >= 1 && TextUtils.isEmpty(strArr[0])) {
                    return null;
                }
                String str = strArr[0];
                c.j.a.a.a.c.d dVar = s.this.m;
                if (!(dVar == null || TextUtils.isEmpty(dVar.n()))) {
                    obj = c.j.a.d.b.e.i.a(y.a()).b(str, s.this.m.n());
                }
                return obj == null ? i.j().c(y.a(), str) : obj;
            }

            public void onPostExecute(Object obj) {
                com.ss.android.socialbase.downloader.g.c cVar = (com.ss.android.socialbase.downloader.g.c) obj;
                c.j.a.d.b.b.g gVar = c.j.a.d.b.b.g.MAIN;
                super.onPostExecute(cVar);
                if (!isCancelled()) {
                    c.j.a.a.a.c.d dVar = s.this.m;
                    if (dVar != null) {
                        try {
                            s sVar;
                            c.j.a.c.g$g.b d = c.j.a.c.q.d.d(dVar.v(), s.this.m.r(), s.this.m.s());
                            if (c.j.a.c.g$g.f.a == null) {
                                synchronized (c.j.a.c.g$g.c.class) {
                                    if (c.j.a.c.g$g.f.a == null) {
                                        c.j.a.c.g$g.f.a = new c.j.a.c.g$g.f();
                                    }
                                }
                            }
                            c.j.a.c.g$g.f.a.a(s.this.m.r(), d.b, c.j.a.c.g$g.d.c.a.b(cVar));
                            boolean a = d.a();
                            c.j.a.d.b.e.i a2;
                            if (cVar == null || cVar.g0() == 0 || (!a && c.j.a.d.b.e.i.a(y.a()).g(cVar))) {
                                if (cVar != null && c.j.a.d.b.e.i.a(y.a()).g(cVar)) {
                                    c.j.a.d.b.o.d.a().e(cVar.g0());
                                    s.this.g = null;
                                }
                                if (s.this.g != null) {
                                    c.j.a.d.b.e.i.a(y.a()).n(s.this.g.g0());
                                    sVar = s.this;
                                    if (sVar.r) {
                                        c.j.a.d.b.e.i.a(sVar.m()).d(s.this.g.g0(), s.this.i, false);
                                    } else {
                                        a2 = c.j.a.d.b.e.i.a(sVar.m());
                                        int g0 = s.this.g.g0();
                                        c.j.a.d.b.d.b bVar = s.this.i;
                                        Objects.requireNonNull(a2);
                                        if (bVar != null) {
                                            c.j.a.d.b.e.d.b().f(g0, bVar, gVar, true);
                                        }
                                    }
                                }
                                if (a) {
                                    sVar = s.this;
                                    sVar.g = new com.ss.android.socialbase.downloader.g.c.b(sVar.m.a()).a();
                                    s.this.g.b0(-3);
                                    sVar = s.this;
                                    sVar.b.b(sVar.g, s.h(sVar), x.a(s.this.e));
                                } else {
                                    Iterator it = ((ArrayList) x.a(s.this.e)).iterator();
                                    while (it.hasNext()) {
                                        ((c.j.a.a.a.c.e) it.next()).a();
                                    }
                                    s.this.g = null;
                                }
                            } else {
                                c.j.a.d.b.e.i.a(y.a()).n(cVar.g0());
                                com.ss.android.socialbase.downloader.g.c cVar2 = s.this.g;
                                if (cVar2 == null || cVar2.o0() != -4) {
                                    s sVar2 = s.this;
                                    sVar2.g = cVar;
                                    if (sVar2.r) {
                                        c.j.a.d.b.e.i.a(y.a()).d(s.this.g.g0(), s.this.i, false);
                                    } else {
                                        a2 = c.j.a.d.b.e.i.a(y.a());
                                        int g02 = s.this.g.g0();
                                        c.j.a.d.b.d.b bVar2 = s.this.i;
                                        Objects.requireNonNull(a2);
                                        if (bVar2 != null) {
                                            c.j.a.d.b.e.d.b().f(g02, bVar2, gVar, true);
                                        }
                                    }
                                } else {
                                    s.this.g = null;
                                }
                                sVar = s.this;
                                sVar.b.b(sVar.g, s.h(sVar), x.a(s.this.e));
                            }
                            sVar = s.this;
                            sVar.b.c(sVar.g);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }

        /* compiled from: CommonDownloadHandler */
        public class a implements c.j.a.a.a.a.i {
            public void a() {
                String str = s.s;
                s.this.p();
            }

            public void a(String str) {
                str = s.s;
            }
        }

        /* compiled from: CommonDownloadHandler */
        public class b implements d {
            public final /* synthetic */ int a;
            public final /* synthetic */ int b;

            public b(int i, int i2) {
                this.a = i;
                this.b = i2;
            }

            public void a() {
                if (!s.this.c.d.get()) {
                    i.j().f(y.a(), this.a, this.b);
                }
            }
        }

        /* compiled from: CommonDownloadHandler */
        public class c implements d {
            /* JADX WARNING: Removed duplicated region for block: B:208:0x04d7  */
            /* JADX WARNING: Removed duplicated region for block: B:40:0x011c  */
            /* JADX WARNING: Removed duplicated region for block: B:39:0x0112  */
            /* JADX WARNING: Removed duplicated region for block: B:109:0x02fe  */
            /* JADX WARNING: Removed duplicated region for block: B:108:0x02fc  */
            /* JADX WARNING: Removed duplicated region for block: B:113:0x030b  */
            /* JADX WARNING: Removed duplicated region for block: B:112:0x0309  */
            /* JADX WARNING: Removed duplicated region for block: B:117:0x0318  */
            /* JADX WARNING: Removed duplicated region for block: B:116:0x0316  */
            /* JADX WARNING: Removed duplicated region for block: B:121:0x0326  */
            /* JADX WARNING: Removed duplicated region for block: B:120:0x0324  */
            /* JADX WARNING: Removed duplicated region for block: B:125:0x033d  */
            /* JADX WARNING: Removed duplicated region for block: B:124:0x033b  */
            /* JADX WARNING: Removed duplicated region for block: B:135:0x036a  */
            /* JADX WARNING: Removed duplicated region for block: B:148:0x03b9  */
            /* JADX WARNING: Removed duplicated region for block: B:147:0x03ae  */
            /* JADX WARNING: Removed duplicated region for block: B:152:0x03cf  */
            /* JADX WARNING: Removed duplicated region for block: B:151:0x03c6  */
            /* JADX WARNING: Removed duplicated region for block: B:214:0x04f7  */
            /* JADX WARNING: Removed duplicated region for block: B:249:0x05d7  */
            /* JADX WARNING: Removed duplicated region for block: B:248:0x05d5  */
            /* JADX WARNING: Removed duplicated region for block: B:257:0x05ed  */
            /* JADX WARNING: Missing block: B:52:0x0174, code skipped:
            if (r0.startsWith(r10.getAbsolutePath()) != false) goto L_0x0204;
     */
            public void a() {
                /*
                r23 = this;
                r1 = r23;
                r0 = c.j.a.c.g.s.this;
                r0 = r0.c;
                r0 = r0.d;
                r0 = r0.get();
                if (r0 == 0) goto L_0x000f;
            L_0x000e:
                return;
            L_0x000f:
                r2 = c.j.a.c.g.s.this;
                r3 = c.j.a.c.o.b.b.a;
                r0 = r2.e;
                r0 = c.j.a.c.g.x.a(r0);
                r0 = (java.util.ArrayList) r0;
                r0 = r0.iterator();
            L_0x001f:
                r4 = r0.hasNext();
                if (r4 == 0) goto L_0x0035;
            L_0x0025:
                r4 = r0.next();
                r4 = (c.j.a.a.a.c.e) r4;
                r5 = r2.m;
                r6 = r2.o();
                r4.a(r5, r6);
                goto L_0x001f;
            L_0x0035:
                r4 = r2.b;
                r5 = c.j.a.c.g.y.a();
                r6 = r2.i;
                java.util.Objects.requireNonNull(r4);
                r8 = 2;
                r9 = 1;
                if (r5 != 0) goto L_0x0047;
            L_0x0044:
                r10 = 0;
                goto L_0x04f9;
            L_0x0047:
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.j();
                r11 = new java.util.ArrayList;
                r11.<init>();
                if (r0 == 0) goto L_0x0081;
            L_0x0056:
                r0 = r0.entrySet();
                r0 = r0.iterator();
            L_0x005e:
                r12 = r0.hasNext();
                if (r12 == 0) goto L_0x0081;
            L_0x0064:
                r12 = r0.next();
                r12 = (java.util.Map.Entry) r12;
                if (r12 == 0) goto L_0x005e;
            L_0x006c:
                r13 = new com.ss.android.socialbase.downloader.g.e;
                r14 = r12.getKey();
                r14 = (java.lang.String) r14;
                r12 = r12.getValue();
                r12 = (java.lang.String) r12;
                r13.m4697init(r14, r12);
                r11.add(r13);
                goto L_0x005e;
            L_0x0081:
                r0 = r4.b;
                r0 = r0.b;
                r12 = r0.d();
                r0 = java.lang.String.valueOf(r12);
                r12 = r4.b;
                r12 = r12.b;
                r12 = r12.c();
                r13 = r4.b;
                r13 = r13.b;
                r13 = r13.k();
                r14 = r4.b;
                r14 = r14.b;
                r14 = r14.B();
                r14 = java.lang.String.valueOf(r14);
                r15 = new org.json.JSONObject;
                r15.<init>();
                r7 = "extra";
                r15.put(r7, r0);	 Catch:{ JSONException -> 0x00c9 }
                r0 = android.text.TextUtils.isEmpty(r12);	 Catch:{ JSONException -> 0x00c9 }
                if (r0 != 0) goto L_0x00be;
            L_0x00b9:
                r0 = "notification_jump_url";
                r15.put(r0, r12);	 Catch:{ JSONException -> 0x00c9 }
            L_0x00be:
                r0 = "show_toast";
                r15.put(r0, r13);	 Catch:{ JSONException -> 0x00c9 }
                r0 = "business_type";
                r15.put(r0, r14);	 Catch:{ JSONException -> 0x00c9 }
                goto L_0x00cd;
            L_0x00c9:
                r0 = move-exception;
                r0.printStackTrace();
            L_0x00cd:
                r7 = r15.toString();
                r0 = r4.b;
                r0 = r0.b;
                r0 = c.j.a.c.g.y.n(r0);
                r12 = c.j.a.d.b.l.a.f(r0);
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.D();
                r13 = r4.b;
                r13 = r13.b;
                r13 = r13.t();
                if (r13 != 0) goto L_0x0103;
            L_0x00ef:
                r13 = r4.b;
                r13 = r13.b;
                if (r13 == 0) goto L_0x00fd;
            L_0x00f5:
                r13 = r13.B();
                if (r13 != r8) goto L_0x00fd;
            L_0x00fb:
                r13 = 1;
                goto L_0x00fe;
            L_0x00fd:
                r13 = 0;
            L_0x00fe:
                if (r13 == 0) goto L_0x0101;
            L_0x0100:
                goto L_0x0103;
            L_0x0101:
                r13 = r0;
                goto L_0x0104;
            L_0x0103:
                r13 = 4;
            L_0x0104:
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.n();
                r0 = android.text.TextUtils.isEmpty(r0);
                if (r0 != 0) goto L_0x011c;
            L_0x0112:
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.n();
                goto L_0x0204;
            L_0x011c:
                r0 = c.j.a.d.a.i.j();
                r15 = c.j.a.c.g.y.a();
                r8 = r4.b;
                r8 = r8.b;
                r8 = r8.a();
                r8 = r0.c(r15, r8);
                r0 = c.j.a.c.q.c.a;
                r0 = c.j.a.c.g.y.r();
                r15 = c.j.a.c.g.y.a();
                r14 = "android.permission.WRITE_EXTERNAL_STORAGE";
                r14 = r0.a(r15, r14);
                if (r8 == 0) goto L_0x018b;
            L_0x0142:
                r0 = r8.e;
                r0 = android.text.TextUtils.isEmpty(r0);
                if (r0 != 0) goto L_0x018b;
            L_0x014a:
                r0 = r8.e;
                if (r14 == 0) goto L_0x0150;
            L_0x014e:
                goto L_0x0204;
            L_0x0150:
                r15 = android.os.Environment.getDataDirectory();
                r15 = r15.getAbsolutePath();
                r15 = r0.startsWith(r15);
                if (r15 == 0) goto L_0x0160;
            L_0x015e:
                goto L_0x0204;
            L_0x0160:
                r15 = c.j.a.c.g.y.a();	 Catch:{ Exception -> 0x0178 }
                r10 = android.os.Environment.DIRECTORY_DOWNLOADS;	 Catch:{ Exception -> 0x0178 }
                r10 = r15.getExternalFilesDir(r10);	 Catch:{ Exception -> 0x0178 }
                if (r10 == 0) goto L_0x017c;
            L_0x016c:
                r10 = r10.getAbsolutePath();	 Catch:{ Exception -> 0x0178 }
                r10 = r0.startsWith(r10);	 Catch:{ Exception -> 0x0178 }
                if (r10 == 0) goto L_0x017c;
            L_0x0176:
                goto L_0x0204;
            L_0x0178:
                r0 = move-exception;
                r0.printStackTrace();
            L_0x017c:
                r0 = c.j.a.d.b.e.b.a();
                r0 = c.j.a.d.b.e.i.a(r0);
                r8 = r8.g0();
                r0.e(r8, r9);
            L_0x018b:
                r8 = new org.json.JSONObject;
                r8.<init>();
                r0 = "ttdownloader_code";
                if (r14 == 0) goto L_0x0196;
            L_0x0194:
                r10 = 1;
                goto L_0x0197;
            L_0x0196:
                r10 = 2;
            L_0x0197:
                r10 = java.lang.Integer.valueOf(r10);	 Catch:{ JSONException -> 0x019f }
                r8.putOpt(r0, r10);	 Catch:{ JSONException -> 0x019f }
                goto L_0x01a3;
            L_0x019f:
                r0 = move-exception;
                r0.printStackTrace();
            L_0x01a3:
                r0 = r4.b;
                r10 = "label_external_permission";
                r3.o(r10, r8, r0);
                r0 = c.j.a.d.a.h.l();	 Catch:{ Exception -> 0x01af }
                goto L_0x01b0;
            L_0x01af:
                r0 = 0;
            L_0x01b0:
                r8 = "external_storage_permission_path_type";
                r10 = 0;
                r8 = r12.b(r8, r10);
                if (r8 == 0) goto L_0x0204;
            L_0x01b9:
                r10 = 4;
                if (r8 == r10) goto L_0x01e9;
            L_0x01bc:
                if (r14 != 0) goto L_0x01c2;
            L_0x01be:
                r10 = 2;
                if (r8 != r10) goto L_0x01c2;
            L_0x01c1:
                goto L_0x01e9;
            L_0x01c2:
                r10 = 3;
                if (r8 == r10) goto L_0x01c9;
            L_0x01c5:
                if (r14 != 0) goto L_0x0204;
            L_0x01c7:
                if (r8 != r9) goto L_0x0204;
            L_0x01c9:
                r8 = c.j.a.c.g.y.a();
                r10 = android.os.Environment.DIRECTORY_DOWNLOADS;
                r8 = r8.getExternalFilesDir(r10);
                if (r8 == 0) goto L_0x0204;
            L_0x01d5:
                r10 = r8.exists();
                if (r10 != 0) goto L_0x01de;
            L_0x01db:
                r8.mkdirs();
            L_0x01de:
                r10 = r8.exists();
                if (r10 == 0) goto L_0x0204;
            L_0x01e4:
                r0 = r8.getAbsolutePath();
                goto L_0x0204;
            L_0x01e9:
                r8 = c.j.a.c.g.y.a();
                r8 = r8.getFilesDir();
                r10 = r8.exists();
                if (r10 != 0) goto L_0x01fa;
            L_0x01f7:
                r8.mkdirs();
            L_0x01fa:
                r10 = r8.exists();
                if (r10 == 0) goto L_0x0204;
            L_0x0200:
                r0 = r8.getAbsolutePath();
            L_0x0204:
                r8 = r4.b;
                r8 = r8.b;
                r8 = r8.a();
                r8 = c.j.a.d.b.e.b.c(r8, r0);
                r10 = c.j.a.c.g.y.a();
                r10 = c.j.a.d.b.e.i.a(r10);
                r8 = r10.k(r8);
                if (r8 == 0) goto L_0x022e;
            L_0x021e:
                r10 = r4.b;
                r10 = r10.b;
                r10 = r10.B();
                r14 = 3;
                if (r14 != r10) goto L_0x022e;
            L_0x0229:
                r8.V = r9;
                c.j.a.d.b.n.a.n(r8, r9);
            L_0x022e:
                r8 = new c.j.a.d.a.l;
                r10 = r4.b;
                r10 = r10.b;
                r10 = r10.a();
                r8.m2349init(r5, r10);
                r5 = r4.b;
                r5 = r5.b;
                r5 = r5.b();
                r8.c = r5;
                r5 = r4.b;
                r5 = r5.b;
                r5 = r5.h();
                r8.d = r5;
                r8.l = r7;
                r8.g = r11;
                r5 = r4.b;
                r5 = r5.b;
                r5 = r5.l();
                r8.h = r5;
                r5 = r4.b;
                r5 = r5.b;
                r5 = r5.m();
                r8.j = r5;
                r5 = r4.b;
                r5 = r5.b;
                r5 = r5.o();
                r8.e = r5;
                r8.f = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.w();
                r8.M = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.e();
                r8.t = r0;
                r0 = r4.b;
                r0 = r0.b;
                r10 = r0.f();
                r8.u = r10;
                r8.k = r6;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.q();
                if (r0 != 0) goto L_0x02a9;
            L_0x029d:
                r0 = "need_independent_process";
                r5 = 0;
                r0 = r12.b(r0, r5);
                if (r0 != r9) goto L_0x02a7;
            L_0x02a6:
                goto L_0x02a9;
            L_0x02a7:
                r0 = 0;
                goto L_0x02aa;
            L_0x02a9:
                r0 = 1;
            L_0x02aa:
                r8.D = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.z();
                r8.I = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.y();
                r8.i = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.v();
                r8.s = r0;
                r0 = 1000; // 0x3e8 float:1.401E-42 double:4.94E-321;
                r8.F = r0;
                r0 = 100;
                r8.G = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = c.j.a.c.g.y.n(r0);
                r8.L = r0;
                r8.A = r9;
                r8.B = r9;
                r0 = 5;
                r5 = "retry_count";
                r0 = r12.b(r5, r0);
                r8.w = r0;
                r0 = "backup_url_retry_count";
                r5 = 0;
                r0 = r12.b(r0, r5);
                r8.x = r0;
                r8.B = r9;
                r0 = "need_head_connection";
                r0 = r12.b(r0, r9);
                if (r0 != r9) goto L_0x02fe;
            L_0x02fc:
                r0 = 1;
                goto L_0x02ff;
            L_0x02fe:
                r0 = 0;
            L_0x02ff:
                r8.H = r0;
                r0 = "need_https_to_http_retry";
                r0 = r12.b(r0, r5);
                if (r0 != r9) goto L_0x030b;
            L_0x0309:
                r0 = 1;
                goto L_0x030c;
            L_0x030b:
                r0 = 0;
            L_0x030c:
                r8.n = r0;
                r0 = "need_chunk_downgrade_retry";
                r0 = r12.b(r0, r9);
                if (r0 != r9) goto L_0x0318;
            L_0x0316:
                r0 = 1;
                goto L_0x0319;
            L_0x0318:
                r0 = 0;
            L_0x0319:
                r8.K = r0;
                r0 = "need_retry_delay";
                r5 = 0;
                r0 = r12.b(r0, r5);
                if (r0 != r9) goto L_0x0326;
            L_0x0324:
                r0 = 1;
                goto L_0x0327;
            L_0x0326:
                r0 = 0;
            L_0x0327:
                r8.y = r0;
                r6 = "";
                r0 = "retry_delay_time_array";
                r0 = r12.g(r0, r6);
                r8.z = r0;
                r0 = "need_reuse_runnable";
                r0 = r12.b(r0, r5);
                if (r0 != r9) goto L_0x033d;
            L_0x033b:
                r0 = 1;
                goto L_0x033e;
            L_0x033d:
                r0 = 0;
            L_0x033e:
                r8.C = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.a();
                r5 = r4.b;
                r5 = r5.b;
                r5 = r5.p();
                r7 = "download_chunk_config";
                if (r5 == 0) goto L_0x0366;
            L_0x0354:
                r10 = r5.has(r7);
                if (r10 == 0) goto L_0x0366;
            L_0x035a:
                r10 = c.j.a.d.b.l.a.n(r7);
                if (r10 != 0) goto L_0x0366;
            L_0x0360:
                r0 = new c.j.a.c.g$m;
                r0.m6343init(r5);
                goto L_0x037d;
            L_0x0366:
                r5 = c.h.a.m0.r.a.a;
                if (r5 != 0) goto L_0x0375;
            L_0x036a:
                r5 = new c.j.a.c.g$m;
                r10 = c.j.a.c.g.y.t();
                r5.m6343init(r10);
                c.h.a.m0.r.a.a = r5;
            L_0x0375:
                r5 = new c.j.a.c.g$l;
                r10 = c.h.a.m0.r.a.a;
                r5.m6342init(r10, r0);
                r0 = r5;
            L_0x037d:
                r8.p = r0;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.p();
                if (r0 == 0) goto L_0x039b;
            L_0x0389:
                r5 = r0.has(r7);
                if (r5 == 0) goto L_0x039b;
            L_0x038f:
                r5 = c.j.a.d.b.l.a.n(r7);
                if (r5 != 0) goto L_0x039b;
            L_0x0395:
                r5 = new c.j.a.c.g$n;
                r5.m6344init(r0);
                goto L_0x039c;
            L_0x039b:
                r5 = 0;
            L_0x039c:
                r8.o = r5;
                r8.O = r13;
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.i();
                r0 = android.text.TextUtils.isEmpty(r0);
                if (r0 != 0) goto L_0x03b9;
            L_0x03ae:
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.i();
                r8.m = r0;
                goto L_0x03bd;
            L_0x03b9:
                r0 = "application/vnd.android.package-archive";
                r8.m = r0;
            L_0x03bd:
                r0 = "clear_space_use_disk_handler";
                r5 = 0;
                r0 = r12.b(r0, r5);
                if (r0 != r9) goto L_0x03cf;
            L_0x03c6:
                r0 = new c.j.a.c.g$i.a;
                r0.m6341init();
                r8.J = r0;
                r5 = r0;
                goto L_0x03d0;
            L_0x03cf:
                r5 = 0;
            L_0x03d0:
                r0 = r4.b;
                r7 = r0.b;
                if (r7 == 0) goto L_0x03f0;
            L_0x03d6:
                r0 = r7.v();
                r0 = android.text.TextUtils.isEmpty(r0);
                if (r0 != 0) goto L_0x03f0;
            L_0x03e0:
                r0 = r4.b;
                r0 = r0.b;
                r0 = r0.a();
                r0 = android.text.TextUtils.isEmpty(r0);
                if (r0 != 0) goto L_0x03f0;
            L_0x03ee:
                r0 = 1;
                goto L_0x03f1;
            L_0x03f0:
                r0 = 0;
            L_0x03f1:
                if (r0 == 0) goto L_0x03ff;
            L_0x03f3:
                r0 = r4.b;
                r0 = r0.d;
                r0 = r0.d();
                if (r0 == 0) goto L_0x03ff;
            L_0x03fd:
                r4 = 1;
                goto L_0x0400;
            L_0x03ff:
                r4 = 0;
            L_0x0400:
                r0 = r8.b;
                r0 = android.text.TextUtils.isEmpty(r0);
                if (r0 != 0) goto L_0x04f4;
            L_0x0408:
                r0 = r8.a;
                if (r0 != 0) goto L_0x040e;
            L_0x040c:
                goto L_0x04f4;
            L_0x040e:
                r0 = c.j.a.d.a.i.j();
                r10 = r0.a(r8);
                r0 = r8.L;
                r11 = c.j.a.d.b.l.a.f(r0);
                r0 = r11.a;
                r12 = "show_unknown_source_on_startup";
                if (r0 == 0) goto L_0x0436;
            L_0x0422:
                r0 = r0.has(r12);
                if (r0 == 0) goto L_0x0436;
            L_0x0428:
                r0 = c.j.a.d.b.l.a.n(r12);
                if (r0 != 0) goto L_0x0436;
            L_0x042e:
                r0 = r11.a;
                r13 = 0;
                r0 = r0.optBoolean(r12, r13);
                goto L_0x043f;
            L_0x0436:
                r13 = 0;
                r0 = c.j.a.d.b.e.b.C();
                r0 = r0.optBoolean(r12, r13);
            L_0x043f:
                if (r0 == 0) goto L_0x04c2;
            L_0x0441:
                r0 = "anti_plans";
                r0 = r11.m(r0);
                r12 = r0.length();
                r13 = 0;
            L_0x044c:
                if (r13 >= r12) goto L_0x0467;
            L_0x044e:
                r14 = r0.optJSONObject(r13);
                if (r14 == 0) goto L_0x0463;
            L_0x0454:
                r15 = "type";
                r15 = r14.optString(r15);
                r9 = "jump_unknown_source";
                r9 = r9.equals(r15);
                if (r9 == 0) goto L_0x0463;
            L_0x0462:
                goto L_0x0468;
            L_0x0463:
                r13 = r13 + 1;
                r9 = 1;
                goto L_0x044c;
            L_0x0467:
                r14 = 0;
            L_0x0468:
                if (r14 == 0) goto L_0x04c2;
            L_0x046a:
                r0 = c.j.a.d.b.e.b.a();
                if (r0 == 0) goto L_0x04c2;
            L_0x0470:
                r9 = "max_jump_count";
                r12 = 0;
                r9 = r14.optInt(r9, r12);
                if (r9 > 0) goto L_0x047a;
            L_0x0479:
                goto L_0x04c2;
            L_0x047a:
                r13 = "sp_anti_hijack_config";
                r13 = r0.getSharedPreferences(r13, r12);
                r15 = "jump_unknown_source_count";
                r1 = r13.getInt(r15, r12);
                if (r1 < r9) goto L_0x0489;
            L_0x0488:
                goto L_0x04c2;
            L_0x0489:
                r9 = c.j.a.d.a.g.e(r0);
                if (r9 != 0) goto L_0x04c2;
            L_0x048f:
                r9 = r13.edit();
                r12 = 1;
                r1 = r1 + r12;
                r1 = r9.putInt(r15, r1);
                r1.apply();
                r1 = new android.content.Intent;
                r9 = com.ss.android.socialbase.appdownloader.view.JumpUnknownSourceActivity.class;
                r1.<init>(r0, r9);
                r9 = 268435456; // 0x10000000 float:2.5243549E-29 double:1.32624737E-315;
                r1.addFlags(r9);
                r9 = "intent";
                r12 = 0;
                r1.putExtra(r9, r12);
                r9 = r14.toString();
                r12 = "config";
                r1.putExtra(r12, r9);
                r9 = 0;
                c.j.a.d.a.g.g(r0, r1, r9);	 Catch:{ all -> 0x04bd }
                r0 = 1;
                goto L_0x04c3;
            L_0x04bd:
                r0 = move-exception;
                r1 = r0;
                c.j.a.d.a.g.b(r1);
            L_0x04c2:
                r0 = 0;
            L_0x04c3:
                if (r0 != 0) goto L_0x04f5;
            L_0x04c5:
                r0 = r7.k();
                if (r0 == 0) goto L_0x04f5;
            L_0x04cb:
                r0 = "download_start_toast_text";
                r0 = r11.g(r0, r6);
                r1 = android.text.TextUtils.isEmpty(r0);
                if (r1 == 0) goto L_0x04de;
            L_0x04d7:
                if (r4 == 0) goto L_0x04dc;
            L_0x04d9:
                r0 = "已开始下载，可在\"我的\"里查看管理";
                goto L_0x04de;
            L_0x04dc:
                r0 = "已开始下载";
            L_0x04de:
                r20 = r0;
                r16 = c.j.a.c.g.y.q();
                r17 = 2;
                r0 = r8.a;
                r21 = 0;
                r22 = 0;
                r18 = r0;
                r19 = r7;
                r16.a(r17, r18, r19, r20, r21, r22);
                goto L_0x04f5;
            L_0x04f4:
                r10 = 0;
            L_0x04f5:
                if (r5 == 0) goto L_0x04f9;
            L_0x04f7:
                r5.a = r10;
            L_0x04f9:
                r0 = r2.m;
                r1 = new c.j.a.b.a.c.a;
                r4 = r2.n();
                r5 = r2.o();
                r1.m2247init(r0, r4, r5, r10);
                r0 = c.j.a.d.b.l.a.d(r10);
                r4 = "download_event_opt";
                r5 = 1;
                r0 = r0.b(r4, r5);
                if (r0 <= r5) goto L_0x0537;
            L_0x0515:
                r0 = r2.m;	 Catch:{ all -> 0x0536 }
                r0 = r0.v();	 Catch:{ all -> 0x0536 }
                r4 = android.text.TextUtils.isEmpty(r0);	 Catch:{ all -> 0x0536 }
                if (r4 != 0) goto L_0x0537;
            L_0x0521:
                r4 = c.j.a.c.g.y.a();	 Catch:{ all -> 0x0536 }
                r4 = r4.getPackageManager();	 Catch:{ all -> 0x0536 }
                r5 = 0;
                r0 = r4.getPackageInfo(r0, r5);	 Catch:{ all -> 0x0536 }
                if (r0 == 0) goto L_0x0532;
            L_0x0530:
                r0 = 1;
                goto L_0x0533;
            L_0x0532:
                r0 = 0;
            L_0x0533:
                r1.A = r0;	 Catch:{ all -> 0x0536 }
                goto L_0x0537;
            L_0x0537:
                r0 = c.j.a.c.g$g.d.c.a;
                r0.e(r1);
                r1.q = r10;
                r4 = java.lang.System.currentTimeMillis();
                r1.O = r4;
                r4 = 0;
                r1.P = r4;
                if (r10 == 0) goto L_0x0563;
            L_0x054a:
                r0 = r2.g;
                if (r0 != 0) goto L_0x055c;
            L_0x054e:
                r0 = r2.b;
                r1 = r0.e;
                if (r1 != 0) goto L_0x0561;
            L_0x0554:
                r1 = new c.j.a.c.g$w;
                r1.m6353init(r0);
                r0.e = r1;
                goto L_0x0561;
            L_0x055c:
                r1 = r2.b;
                r1.d(r0);
            L_0x0561:
                r10 = 0;
                goto L_0x05cf;
            L_0x0563:
                r0 = new com.ss.android.socialbase.downloader.g.c$b;
                r1 = r2.m;
                r1 = r1.a();
                r0.m4688init(r1);
                r0 = r0.a();
                r1 = -1;
                r0.b0(r1);
                r1 = android.os.Message.obtain();
                r4 = 3;
                r1.what = r4;
                r1.obj = r0;
                r0 = r2.a;
                r0.sendMessage(r1);
                r0 = r2.l;
                r4 = new com.ss.android.socialbase.downloader.e.a;
                r5 = "start download failed, id=0";
                r6 = 2;
                r4.m4677init(r6, r5);
                r5 = c.j.a.c.g$g.d.c.a;
                r1 = r5.h(r0);
                r6 = new org.json.JSONObject;
                r6.<init>();
                r0 = "download_time";
                r10 = 0;
                r5 = java.lang.Integer.valueOf(r10);	 Catch:{ JSONException -> 0x05b6 }
                r6.putOpt(r0, r5);	 Catch:{ JSONException -> 0x05b6 }
                r0 = "fail_status";
                r5 = r4.a;	 Catch:{ JSONException -> 0x05b6 }
                r5 = java.lang.Integer.valueOf(r5);	 Catch:{ JSONException -> 0x05b6 }
                r6.putOpt(r0, r5);	 Catch:{ JSONException -> 0x05b6 }
                r0 = "fail_msg";
                r4 = r4.b;	 Catch:{ JSONException -> 0x05b6 }
                r6.putOpt(r0, r4);	 Catch:{ JSONException -> 0x05b6 }
                goto L_0x05bd;
            L_0x05b6:
                r0 = move-exception;
                goto L_0x05ba;
            L_0x05b8:
                r0 = move-exception;
                r10 = 0;
            L_0x05ba:
                r0.printStackTrace();
            L_0x05bd:
                r0 = r1.c;
                r4 = r0.b();
                r7 = r1.b;
                r8 = r1.c;
                r5 = "download_failed";
                r3.m(r4, r5, r6, r7, r8);
                c.j.a.c.q.d.n();
            L_0x05cf:
                r0 = r2.b;
                r1 = r2.g;
                if (r1 == 0) goto L_0x05d7;
            L_0x05d5:
                r1 = 1;
                goto L_0x05d8;
            L_0x05d7:
                r1 = 0;
            L_0x05d8:
                java.util.Objects.requireNonNull(r0);
                if (r1 != 0) goto L_0x05ea;
            L_0x05dd:
                r0 = r0.b;
                r0 = r0.d;
                r0 = r0.b();
                r1 = 1;
                if (r0 != r1) goto L_0x05ea;
            L_0x05e8:
                r9 = 1;
                goto L_0x05eb;
            L_0x05ea:
                r9 = 0;
            L_0x05eb:
                if (r9 == 0) goto L_0x05f0;
            L_0x05ed:
                r2.l();
            L_0x05f0:
                return;
                */
                throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g$s$c.a():void");
            }
        }

        public s() {
            c.j.a.c.q.e eVar = new c.j.a.c.q.e(Looper.getMainLooper(), this);
            this.a = eVar;
            this.i = new a(eVar);
            this.l = -1;
            this.m = null;
            this.n = null;
            this.o = null;
            this.b = new x();
            this.c = new p(eVar);
            this.r = c.j.a.d.b.l.a.f.k("ttdownloader_callback_twice", false);
        }

        public static c.j.a.a.a.e.e h(s sVar) {
            if (sVar.f == null) {
                sVar.f = new c.j.a.a.a.e.e();
            }
            return sVar.f;
        }

        public t a(c.j.a.a.a.c.c cVar) {
            this.n = cVar;
            this.q = n().k() == 0;
            c.j.a.c.g$g.d dVar = c.j.a.c.g$g.d.c.a;
            long j = this.l;
            c.j.a.a.a.c.c n = n();
            Objects.requireNonNull(dVar);
            if (n != null) {
                dVar.c.put(Long.valueOf(j), n);
            }
            return this;
        }

        public t b(Context context) {
            if (context != null) {
                this.d = new WeakReference(context);
            }
            y.o(context);
            return this;
        }

        public /* synthetic */ t c(int i, c.j.a.a.a.c.e eVar) {
            g(i, eVar);
            return this;
        }

        public t d(c.j.a.a.a.a.j jVar) {
            if (jVar == null) {
                this.p = null;
            } else {
                this.p = new SoftReference(jVar);
            }
            return this;
        }

        public t e(c.j.a.a.a.c.d dVar) {
            if (dVar != null) {
                c.j.a.c.g$g.d dVar2 = c.j.a.c.g$g.d.c.a;
                Objects.requireNonNull(dVar2);
                dVar2.b.put(Long.valueOf(dVar.d()), dVar);
                if (dVar.x() != null) {
                    c.j.a.a.a.e.b x = dVar.x();
                    dVar.d();
                    Objects.requireNonNull(x);
                    x = dVar.x();
                    dVar.v();
                    Objects.requireNonNull(x);
                }
                this.l = dVar.d();
                this.m = dVar;
                if (c.h.a.m0.r.a.n(dVar)) {
                    ((c.j.a.b.a.a.c) dVar).b = 3;
                    c.j.a.b.a.c.a g = c.j.a.c.g$g.d.c.a.g(this.l);
                    if (!(g == null || g.b == 3)) {
                        g.b = 3;
                        c.j.a.c.g$g.g.b.a.a(g);
                    }
                }
            }
            return this;
        }

        public t f(c.j.a.a.a.c.b bVar) {
            this.o = bVar;
            c.j.a.c.g$g.d dVar = c.j.a.c.g$g.d.c.a;
            long j = this.l;
            c.j.a.a.a.c.b o = o();
            Objects.requireNonNull(dVar);
            if (o != null) {
                dVar.d.put(Long.valueOf(j), o);
            }
            return this;
        }

        public void g() {
            c.j.a.c.g$g.d dVar = c.j.a.c.g$g.d.c.a;
            long j = this.l;
            dVar.b.remove(Long.valueOf(j));
            dVar.c.remove(Long.valueOf(j));
            dVar.d.remove(Long.valueOf(j));
        }

        /* JADX WARNING: Removed duplicated region for block: B:15:0x0030  */
        /* JADX WARNING: Removed duplicated region for block: B:14:0x002c  */
        public final void i(boolean r6) {
            /*
            r5 = this;
            r0 = r5.b;
            r1 = r5.q;
            r2 = r0.b;
            r2 = r2.b;
            r2 = c.j.a.c.q.d.l(r2);
            r3 = 0;
            r4 = 1;
            if (r2 == 0) goto L_0x0024;
        L_0x0010:
            r0 = r0.b;
            r0 = r0.d;
            r0 = r0.a();
            if (r0 == 0) goto L_0x001f;
        L_0x001a:
            if (r0 != r4) goto L_0x001d;
        L_0x001c:
            goto L_0x001f;
        L_0x001d:
            r0 = 0;
            goto L_0x0020;
        L_0x001f:
            r0 = 1;
        L_0x0020:
            if (r0 != 0) goto L_0x0024;
        L_0x0022:
            r0 = 1;
            goto L_0x0025;
        L_0x0024:
            r0 = 0;
        L_0x0025:
            if (r0 == 0) goto L_0x002a;
        L_0x0027:
            if (r1 == 0) goto L_0x002a;
        L_0x0029:
            r3 = 1;
        L_0x002a:
            if (r3 == r4) goto L_0x0030;
        L_0x002c:
            r5.k(r6);
            goto L_0x003c;
        L_0x0030:
            if (r6 == 0) goto L_0x0039;
        L_0x0032:
            r6 = c.j.a.c.o.b.b.a;
            r0 = r5.l;
            r6.c(r0, r4);
        L_0x0039:
            r5.l();
        L_0x003c:
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g$s.i(boolean):void");
        }

        /* JADX WARNING: Removed duplicated region for block: B:26:0x0051  */
        public final void j(boolean r6) {
            /*
            r5 = this;
            r0 = 1;
            if (r6 == 0) goto L_0x000a;
        L_0x0003:
            r1 = c.j.a.c.o.b.b.a;
            r2 = r5.l;
            r1.c(r2, r0);
        L_0x000a:
            r1 = r5.b;
            r2 = r5.g;
            java.util.Objects.requireNonNull(r1);
            r3 = 0;
            if (r2 == 0) goto L_0x001d;
        L_0x0014:
            r2 = r2.o0();
            r4 = -3;
            if (r2 != r4) goto L_0x001d;
        L_0x001b:
            r2 = 1;
            goto L_0x001e;
        L_0x001d:
            r2 = 0;
        L_0x001e:
            if (r2 == 0) goto L_0x002c;
        L_0x0020:
            r2 = r1.b;
            r2 = r2.b;
            r2 = c.j.a.c.q.d.l(r2);
            if (r2 != 0) goto L_0x002c;
        L_0x002a:
            r2 = 1;
            goto L_0x002d;
        L_0x002c:
            r2 = 0;
        L_0x002d:
            if (r2 != 0) goto L_0x0052;
        L_0x002f:
            r2 = r1.b;
            r2 = r2.b;
            r2 = c.j.a.c.q.d.l(r2);
            if (r2 == 0) goto L_0x004d;
        L_0x0039:
            r1 = r1.b;
            r1 = r1.d;
            r1 = r1.a();
            if (r1 == 0) goto L_0x0048;
        L_0x0043:
            if (r1 != r0) goto L_0x0046;
        L_0x0045:
            goto L_0x0048;
        L_0x0046:
            r1 = 0;
            goto L_0x0049;
        L_0x0048:
            r1 = 1;
        L_0x0049:
            if (r1 == 0) goto L_0x004d;
        L_0x004b:
            r1 = 1;
            goto L_0x004e;
        L_0x004d:
            r1 = 0;
        L_0x004e:
            if (r1 == 0) goto L_0x0051;
        L_0x0050:
            goto L_0x0052;
        L_0x0051:
            r0 = 0;
        L_0x0052:
            if (r0 == 0) goto L_0x0058;
        L_0x0054:
            r5.k(r6);
            goto L_0x005b;
        L_0x0058:
            r5.l();
        L_0x005b:
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g$s.j(boolean):void");
        }

        /* JADX WARNING: Missing block: B:8:0x0034, code skipped:
            if (r1 == false) goto L_0x016f;
     */
        public final void k(boolean r14) {
            /*
            r13 = this;
            r0 = c.j.a.c.o.b.b.a;
            r1 = r13.g;
            r2 = 1;
            r3 = 0;
            r4 = "type";
            r5 = 268435456; // 0x10000000 float:2.5243549E-29 double:1.32624737E-315;
            if (r1 == 0) goto L_0x016f;
        L_0x000c:
            r1 = r1.o0();
            r6 = -3;
            if (r1 == r6) goto L_0x0038;
        L_0x0013:
            r1 = c.j.a.c.g.y.a();
            r1 = c.j.a.d.b.e.i.a(r1);
            r6 = r13.g;
            r6 = r6.g0();
            java.util.Objects.requireNonNull(r1);
            r1 = c.j.a.d.b.e.d.b();
            r1 = r1.h(r6);
            if (r1 != 0) goto L_0x0030;
        L_0x002e:
            r1 = 0;
            goto L_0x0034;
        L_0x0030:
            r1 = r1.b(r6);
        L_0x0034:
            if (r1 != 0) goto L_0x0038;
        L_0x0036:
            goto L_0x016f;
        L_0x0038:
            r14 = r13.g;
            r14.o0();
            r14 = r13.b;
            r1 = r13.g;
            r14.d(r1);
            r14 = r13.g;
            if (r14 == 0) goto L_0x0052;
        L_0x0048:
            r1 = r13.m;
            if (r1 == 0) goto L_0x0052;
        L_0x004c:
            r1 = r1.m();
            r14.g = r1;
        L_0x0052:
            r14 = r13.g;
            r14 = r14.o0();
            r1 = r13.g;
            r7 = r1.g0();
            r1 = c.j.a.c.g$g.d.c.a;
            r6 = r13.g;
            r1 = r1.b(r6);
            r6 = -4;
            if (r14 == r6) goto L_0x012f;
        L_0x0069:
            r6 = -2;
            if (r14 == r6) goto L_0x012f;
        L_0x006c:
            r6 = -1;
            if (r14 != r6) goto L_0x0071;
        L_0x006f:
            goto L_0x012f;
        L_0x0071:
            r6 = c.j.a.c.g.y.h(r14);
            if (r6 == 0) goto L_0x007e;
        L_0x0077:
            r6 = r13.c;
            r6 = r6.d;
            r6.set(r2);
        L_0x007e:
            r6 = c.j.a.d.a.i.j();
            r8 = c.j.a.c.g.y.a();
            r6.f(r8, r7, r14);
            r6 = r13.g;
            if (r1 == 0) goto L_0x012a;
        L_0x008d:
            if (r6 != 0) goto L_0x0091;
        L_0x008f:
            goto L_0x012a;
        L_0x0091:
            r7 = r6.g0();
            r8 = c.j.a.d.b.l.a.d(r7);
            r9 = "pause_reserve_on_wifi";
            r8 = r8.b(r9, r3);
            if (r8 != r2) goto L_0x00a3;
        L_0x00a1:
            r8 = 1;
            goto L_0x00a4;
        L_0x00a3:
            r8 = 0;
        L_0x00a4:
            r10 = new org.json.JSONObject;
            r10.<init>();
            r11 = "switch_status";
            if (r8 == 0) goto L_0x00af;
        L_0x00ad:
            r12 = 1;
            goto L_0x00b0;
        L_0x00af:
            r12 = 0;
        L_0x00b0:
            r12 = java.lang.Integer.valueOf(r12);	 Catch:{ Exception -> 0x00b8 }
            r10.putOpt(r11, r12);	 Catch:{ Exception -> 0x00b8 }
            goto L_0x00bc;
        L_0x00b8:
            r11 = move-exception;
            r11.printStackTrace();
        L_0x00bc:
            r11 = "pause_reserve_wifi_switch_status";
            r0.n(r11, r10, r1);
            if (r8 != 0) goto L_0x00c5;
        L_0x00c3:
            goto L_0x0220;
        L_0x00c5:
            r14 = c.j.a.c.g.y.h(r14);
            if (r14 != 0) goto L_0x00cd;
        L_0x00cb:
            goto L_0x0220;
        L_0x00cd:
            r14 = c.j.a.c.g.y.a();
            r14 = c.j.a.d.b.n.a.t(r14);
            if (r14 == 0) goto L_0x00e7;
        L_0x00d7:
            r14 = r6.h();
            if (r14 == 0) goto L_0x0220;
        L_0x00dd:
            r6.j();
            r14 = "pause_reserve_wifi_cancel_on_wifi";
            r0.i(r14, r1);
            goto L_0x0220;
        L_0x00e7:
            r6.N();
            r14 = r6.C0;	 Catch:{ Exception -> 0x00f1 }
            r14 = r14.optInt(r9, r3);	 Catch:{ Exception -> 0x00f1 }
            goto L_0x00f2;
        L_0x00f1:
            r14 = 0;
        L_0x00f2:
            r14 = r14 & r2;
            if (r14 <= 0) goto L_0x00f6;
        L_0x00f5:
            goto L_0x00f7;
        L_0x00f6:
            r2 = 0;
        L_0x00f7:
            if (r2 != 0) goto L_0x0220;
        L_0x00f9:
            r14 = new c.j.a.c.g$z;
            r14.m6359init(r7, r1);
            c.j.a.c.g.y.l = r14;
            r0 = r1.a;
            r14 = com.ss.android.downloadlib.activity.TTDelegateActivity.b;
            r14 = new android.content.Intent;
            r2 = c.j.a.c.g.y.a();
            r3 = com.ss.android.downloadlib.activity.TTDelegateActivity.class;
            r14.<init>(r2, r3);
            r14.addFlags(r5);
            r2 = 5;
            r14.putExtra(r4, r2);
            r2 = "model_id";
            r14.putExtra(r2, r0);
            r0 = c.j.a.c.g.y.a();
            if (r0 == 0) goto L_0x0220;
        L_0x0121:
            r0 = c.j.a.c.g.y.a();
            r0.startActivity(r14);
            goto L_0x0220;
        L_0x012a:
            c.j.a.c.q.d.n();
            goto L_0x0220;
        L_0x012f:
            if (r1 == 0) goto L_0x013f;
        L_0x0131:
            r4 = java.lang.System.currentTimeMillis();
            r1.O = r4;
            r0 = r13.g;
            r4 = r0.I();
            r1.P = r4;
        L_0x013f:
            r0 = r13.g;
            r0.G0 = r3;
            r0 = r13.c;
            r8 = new c.j.a.c.g$g.d$b;
            r2 = r13.l;
            r4 = r13.m;
            r5 = r13.n();
            r6 = r13.o();
            r1 = r8;
            r1.m2271init(r2, r4, r5, r6);
            r0.b = r8;
            r6 = r13.c;
            r0 = r13.g;
            r8 = r0.I();
            r0 = r13.g;
            r10 = r0.T;
            r12 = new c.j.a.c.g$s$b;
            r12.m6348init(r7, r14);
            r6.a(r7, r8, r10, r12);
            goto L_0x0220;
        L_0x016f:
            if (r14 == 0) goto L_0x0177;
        L_0x0171:
            r6 = r13.l;
            r14 = 2;
            r0.c(r6, r14);
        L_0x0177:
            r14 = r13.m;
            r14 = c.j.a.c.g.y.n(r14);
            r14 = c.j.a.d.b.l.a.f(r14);
            r0 = "external_storage_permission_path_type";
            r14 = r14.b(r0, r3);
            if (r14 == 0) goto L_0x018e;
        L_0x0189:
            r13.p();
            goto L_0x0220;
        L_0x018e:
            r14 = r13.b;
            r0 = new c.j.a.c.g$s$a;
            r0.m6347init();
            r1 = r14.b;
            r1 = r1.b;
            r1 = r1.n();
            r1 = android.text.TextUtils.isEmpty(r1);
            if (r1 != 0) goto L_0x01bd;
        L_0x01a3:
            r1 = r14.b;
            r1 = r1.b;
            r1 = r1.n();
            r3 = android.os.Environment.getDataDirectory();
            r3 = r3.getAbsolutePath();
            r1 = r1.startsWith(r3);
            if (r1 == 0) goto L_0x01bd;
        L_0x01b9:
            r0.a();
            goto L_0x0220;
        L_0x01bd:
            r1 = new c.j.a.c.g$u;
            r1.m6351init(r14, r0);
            r0 = c.j.a.c.q.c.a;
            r0 = c.j.a.c.g.y.r();
            r3 = c.j.a.c.g.y.a();
            r6 = "android.permission.WRITE_EXTERNAL_STORAGE";
            r0 = r0.a(r3, r6);
            if (r0 == 0) goto L_0x01da;
        L_0x01d4:
            r14 = r1.a;
            r14.a();
            goto L_0x0220;
        L_0x01da:
            r0 = new java.lang.String[]{r6};
            r3 = new c.j.a.c.g$v;
            r3.m6352init(r14, r1);
            r6 = java.lang.System.currentTimeMillis();
            r14 = java.lang.String.valueOf(r6);
            r1 = android.text.TextUtils.isEmpty(r14);
            if (r1 != 0) goto L_0x01f6;
        L_0x01f1:
            r1 = c.j.a.c.q.c.a;
            r1.put(r14, r3);
        L_0x01f6:
            r1 = com.ss.android.downloadlib.activity.TTDelegateActivity.b;
            r1 = new android.content.Intent;
            r3 = c.j.a.c.g.y.a();
            r6 = com.ss.android.downloadlib.activity.TTDelegateActivity.class;
            r1.<init>(r3, r6);
            r1.addFlags(r5);
            r1.putExtra(r4, r2);
            r2 = "permission_id_key";
            r1.putExtra(r2, r14);
            r14 = "permission_content_key";
            r1.putExtra(r14, r0);
            r14 = c.j.a.c.g.y.a();
            if (r14 == 0) goto L_0x0220;
        L_0x0219:
            r14 = c.j.a.c.g.y.a();
            r14.startActivity(r1);
        L_0x0220:
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g$s.k(boolean):void");
        }

        public final void l() {
            SoftReference softReference = this.p;
            if (softReference == null || softReference.get() == null) {
                c.j.a.a.a.a.b p = y.p();
                m();
                o();
                n();
                Objects.requireNonNull((a) p);
                return;
            }
            ((c.j.a.a.a.a.j) this.p.get()).a(this.m, n(), o());
            this.p = null;
        }

        public final Context m() {
            WeakReference weakReference = this.d;
            if (weakReference == null || weakReference.get() == null) {
                return y.a();
            }
            return (Context) this.d.get();
        }

        public final c.j.a.a.a.c.c n() {
            c.j.a.a.a.c.c cVar = this.n;
            return cVar == null ? new c.j.a.a.a.c.g(new c.j.a.a.a.c.g.b(), null) : cVar;
        }

        public final c.j.a.a.a.c.b o() {
            c.j.a.a.a.c.b bVar = this.o;
            return bVar == null ? new c.j.a.b.a.a.a.b().a() : bVar;
        }

        public final void p() {
            this.c.b = new c.j.a.c.g$g.d.b(this.l, this.m, n(), o());
            this.c.a(0, 0, 0, new c());
        }

        public boolean b() {
            return this.j;
        }

        public long d() {
            return this.k;
        }

        public s g(int i, c.j.a.a.a.c.e eVar) {
            if (eVar != null) {
                if (y.t().optInt("back_use_softref_listener") == 1) {
                    this.e.put(Integer.valueOf(i), eVar);
                } else {
                    this.e.put(Integer.valueOf(i), new SoftReference(eVar));
                }
            }
            return this;
        }

        public void a() {
            this.j = true;
            c.j.a.c.g$g.d dVar = c.j.a.c.g$g.d.c.a;
            long j = this.l;
            c.j.a.a.a.c.c n = n();
            Objects.requireNonNull(dVar);
            if (n != null) {
                dVar.c.put(Long.valueOf(j), n);
            }
            dVar = c.j.a.c.g$g.d.c.a;
            j = this.l;
            c.j.a.a.a.c.b o = o();
            Objects.requireNonNull(dVar);
            if (o != null) {
                dVar.d.put(Long.valueOf(j), o);
            }
            x xVar = this.b;
            j = this.l;
            xVar.a = j;
            c.j.a.c.g$g.d.b h = c.j.a.c.g$g.d.c.a.h(j);
            xVar.b = h;
            if (h.a()) {
                c.j.a.c.q.d.n();
            }
            f fVar = this.h;
            if (!(fVar == null || fVar.getStatus() == Status.FINISHED)) {
                this.h.cancel(true);
            }
            fVar = new f(null);
            this.h = fVar;
            try {
                fVar.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new String[]{this.m.a(), this.m.v()});
            } catch (Throwable unused) {
            }
            if (y.t().optInt("enable_empty_listener", 1) == 1 && this.e.get(Integer.valueOf(Integer.MIN_VALUE)) == null) {
                g(Integer.MIN_VALUE, new c.j.a.a.a.a.a());
            }
        }

        public boolean a(int i) {
            if (i == 0) {
                this.e.clear();
            } else {
                this.e.remove(Integer.valueOf(i));
            }
            if (!this.e.isEmpty()) {
                return false;
            }
            this.j = false;
            this.k = System.currentTimeMillis();
            if (this.g != null) {
                c.j.a.d.b.e.i.a(y.a()).n(this.g.g0());
            }
            f fVar = this.h;
            if (!(fVar == null || fVar.getStatus() == Status.FINISHED)) {
                this.h.cancel(true);
            }
            x xVar = this.b;
            com.ss.android.socialbase.downloader.g.c cVar = this.g;
            xVar.c = false;
            b bVar = xVar.e;
            if (bVar != null) {
                c.j.a.c.o.b.b.a.d(((w) bVar).a.a, 2, cVar);
                xVar.e = null;
            }
            com.ss.android.socialbase.downloader.g.c cVar2 = this.g;
            if (cVar2 != null) {
                String str = cVar2.d;
            }
            this.a.removeCallbacksAndMessages(null);
            this.f = null;
            this.g = null;
            return true;
        }

        public void a(boolean z) {
            if (this.g == null) {
                return;
            }
            if (z) {
                c.j.a.c.m.d dVar = i.j().b;
                if (dVar != null) {
                    dVar.b(this.g);
                }
                c.j.a.d.b.e.i.a(c.j.a.d.b.e.b.a()).e(this.g.g0(), true);
                return;
            }
            Intent intent = new Intent(y.a(), DownloadHandlerService.class);
            intent.setAction("android.ss.intent.action.DOWNLOAD_DELETE");
            intent.putExtra("extra_click_download_ids", this.g.g0());
            y.a().startService(intent);
        }

        public void a(long j, int i) {
            if (i == 2 || i == 1) {
                c.j.a.c.g$g.d.b h;
                boolean j2;
                if (j > 0) {
                    c.j.a.a.a.c.d dVar = (c.j.a.a.a.c.d) c.j.a.c.g$g.d.c.a.b.get(Long.valueOf(j));
                    if (dVar != null) {
                        this.m = dVar;
                        this.l = j;
                        x xVar = this.b;
                        xVar.a = j;
                        h = c.j.a.c.g$g.d.c.a.h(j);
                        xVar.b = h;
                        if (h.a()) {
                            c.j.a.c.q.d.n();
                        }
                    }
                } else {
                    c.j.a.c.q.d.n();
                }
                x xVar2 = this.b;
                m();
                c.j.a.b.a.c.a g;
                if (c.j.a.c.q.d.l(xVar2.b.b)) {
                    g = c.j.a.c.g$g.d.c.a.g(xVar2.b.a);
                    if (g != null) {
                        c.j.a.d.b.o.d.a().e(g.q);
                    }
                    j2 = y.j(xVar2.b);
                } else {
                    Object obj = ((xVar2.b.d.b() == 2 && i == 2) || xVar2.b.d.b() == 3) ? 1 : null;
                    if (!(obj == null || TextUtils.isEmpty(xVar2.b.b.v()) || y.t().optInt("disable_market") == 1)) {
                        h = xVar2.b;
                        c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
                        bVar.j("market_click_open", h);
                        c.j.a.c.g$g.e b = y.b(y.a(), h.b.v());
                        int i2 = b.a;
                        if (i2 == 5) {
                            bVar.c(h.a, i);
                            bVar.j("market_open_success", h);
                            c.j.a.a.a.a.b p = y.p();
                            y.a();
                            h.b.v();
                            Objects.requireNonNull((a) p);
                            g = new c.j.a.b.a.c.a(h.b, h.c, h.d, 0);
                            g.d = 2;
                            g.f(System.currentTimeMillis());
                            g.N = 4;
                            c.j.a.c.g$g.d.c.a.e(g);
                            j2 = true;
                        } else if (i2 == 6) {
                            JSONObject jSONObject = new JSONObject();
                            try {
                                jSONObject.putOpt("error_code", Integer.valueOf(b.b));
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            bVar.o("market_open_failed", jSONObject, h);
                        }
                    }
                    j2 = false;
                }
                if (!j2) {
                    if (y.t().optInt("quick_app_enable_switch", 0) == 0) {
                        c.j.a.a.a.c.d dVar2 = this.m;
                        int i3 = j.a;
                        if (!(dVar2 == null || dVar2.E() == null)) {
                            dVar2.E();
                            throw null;
                        }
                    }
                    if (i == 1) {
                        j(true);
                        return;
                    } else if (i == 2) {
                        i(true);
                        return;
                    } else {
                        return;
                    }
                }
                return;
            }
            throw new IllegalArgumentException("error actionType");
        }

        public void a(Message message) {
            Message message2 = message;
            c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
            if (this.j) {
                int i = message2.what;
                int i2 = 0;
                com.bytedance.sdk.openadsdk.downloadnew.a.a.a aVar;
                if (i == 3) {
                    this.g = (com.ss.android.socialbase.downloader.g.c) message2.obj;
                    x xVar = this.b;
                    if (this.f == null) {
                        this.f = new c.j.a.a.a.e.e();
                    }
                    c.j.a.a.a.e.e eVar = this.f;
                    Map map = this.e;
                    Objects.requireNonNull(xVar);
                    if (message2.what == 3) {
                        com.ss.android.socialbase.downloader.g.c cVar = (com.ss.android.socialbase.downloader.g.c) message2.obj;
                        int i3 = message2.arg1;
                        if (!(i3 == 1 || i3 == 6 || i3 != 2)) {
                            if (cVar.V) {
                                x b = x.b();
                                c.j.a.c.g$g.d.b bVar2 = xVar.b;
                                b.a.post(new s(b, bVar2.b, bVar2.d, bVar2.c));
                                cVar.V = false;
                            }
                            c.j.a.b.a.c.a b2 = c.j.a.c.g$g.d.c.a.b(cVar);
                            if (b2 != null) {
                                try {
                                    JSONObject jSONObject = new JSONObject();
                                    bVar.f(cVar, jSONObject);
                                    b2.u = System.currentTimeMillis();
                                    bVar.q(b2.D, "download_resume", jSONObject, b2);
                                    c.j.a.c.g$g.g.b.a.a(b2);
                                } catch (Throwable th) {
                                    th.printStackTrace();
                                }
                            }
                        }
                        eVar.a(cVar);
                        i3 = c.j.a.d.a.h.b(cVar.o0());
                        long j = cVar.T;
                        if (j > 0) {
                            i2 = (int) ((cVar.I() * 100) / j);
                            b bVar3 = xVar.e;
                            if (bVar3 != null) {
                                bVar.d(((w) bVar3).a.a, 2, cVar);
                                xVar.e = null;
                            }
                        }
                        Iterator it = ((ArrayList) x.a(map)).iterator();
                        while (it.hasNext()) {
                            c.j.a.a.a.c.e eVar2 = (c.j.a.a.a.c.e) it.next();
                            if (i3 != 1) {
                                if (i3 == 2) {
                                    eVar2.b(eVar, i2);
                                } else if (i3 == 3) {
                                    if (cVar.o0() == -4) {
                                        eVar2.a();
                                    } else if (cVar.o0() == -1) {
                                        eVar2.a(eVar);
                                    } else if (cVar.o0() == -3) {
                                        if (c.j.a.c.q.d.l(xVar.b.b)) {
                                            eVar2.b(eVar);
                                        } else {
                                            eVar2.c(eVar);
                                        }
                                    }
                                }
                            } else if (cVar.o0() != 11) {
                                eVar2.a(eVar, i2);
                            } else {
                                ArrayList arrayList = new ArrayList();
                                if (!(map == null || map.isEmpty())) {
                                    for (Object next : map.values()) {
                                        if (next instanceof c.j.a.a.a.c.f) {
                                            arrayList.add((c.j.a.a.a.c.f) next);
                                        } else if (next instanceof SoftReference) {
                                            SoftReference softReference = (SoftReference) next;
                                            if (softReference.get() instanceof c.j.a.a.a.c.f) {
                                                arrayList.add((c.j.a.a.a.c.f) softReference.get());
                                            }
                                        }
                                    }
                                }
                                Iterator it2 = arrayList.iterator();
                                while (it2.hasNext()) {
                                    ((c.j.a.a.a.c.f) it2.next()).a(cVar);
                                }
                            }
                        }
                    }
                } else if (i == 4) {
                    aVar = y.i;
                    if (aVar == null || !aVar.a()) {
                        bVar.e(this.l, false, 2);
                        i(false);
                    }
                } else if (i == 5) {
                    aVar = y.i;
                    if (aVar == null || !aVar.a()) {
                        bVar.e(this.l, false, 1);
                        j(false);
                    }
                }
            }
        }
    }

    /* compiled from: DownloadHelper */
    public class u implements c.j.a.a.a.a.i {
        public final /* synthetic */ c.j.a.a.a.a.i a;
        public final /* synthetic */ x b;

        public u(x xVar, c.j.a.a.a.a.i iVar) {
            this.b = xVar;
            this.a = iVar;
        }

        public void a() {
            this.a.a();
        }

        public void a(String str) {
            y.q().a(1, y.a(), this.b.b.b, "您已禁止使用存储权限，请授权后再下载", null, 1);
            c.j.a.c.o.b.b.a.d(this.b.a, 1, null);
            this.a.a(str);
        }
    }

    /* compiled from: DownloadHelper */
    public class v implements c.j.a.c.q.c.a {
        public final /* synthetic */ c.j.a.a.a.a.i a;

        public v(x xVar, c.j.a.a.a.a.i iVar) {
            this.a = iVar;
        }

        public void a() {
            c.j.a.a.a.a.i iVar = this.a;
            if (iVar != null) {
                iVar.a();
            }
        }

        public void a(String str) {
            c.j.a.a.a.a.i iVar = this.a;
            if (iVar != null) {
                iVar.a(str);
            }
        }
    }

    /* compiled from: DownloadHelper */
    public class w implements b {
        public final /* synthetic */ x a;

        public w(x xVar) {
            this.a = xVar;
        }
    }

    /* compiled from: DownloadHelper */
    public class x implements c.j.a.c.q.e.a {
        public long a;
        public c.j.a.c.g$g.d.b b;
        public boolean c = false;
        public final c.j.a.c.q.e d = new c.j.a.c.q.e(Looper.getMainLooper(), this);
        public b e;

        /* compiled from: DownloadHelper */
        public interface b {
        }

        /* compiled from: DownloadHelper */
        public static class a extends c.j.a.d.b.d.a {
            public c.j.a.c.q.e b;

            public a(c.j.a.c.q.e eVar) {
                this.b = eVar;
            }

            public void D(com.ss.android.socialbase.downloader.g.c cVar) {
                d(cVar, -3);
            }

            public void H(com.ss.android.socialbase.downloader.g.c cVar) {
                d(cVar, -4);
            }

            public void P(com.ss.android.socialbase.downloader.g.c cVar) {
                d(cVar, 11);
            }

            public void a(com.ss.android.socialbase.downloader.g.c cVar) {
                d(cVar, 1);
            }

            public void b(com.ss.android.socialbase.downloader.g.c cVar) {
                d(cVar, 2);
            }

            public void c(com.ss.android.socialbase.downloader.g.c cVar) {
                d(cVar, 4);
            }

            public final void d(com.ss.android.socialbase.downloader.g.c cVar, int i) {
                Message obtain = Message.obtain();
                obtain.what = 3;
                obtain.obj = cVar;
                obtain.arg1 = i;
                this.b.sendMessage(obtain);
            }

            public void x(com.ss.android.socialbase.downloader.g.c cVar) {
                d(cVar, -2);
            }

            public void z(com.ss.android.socialbase.downloader.g.c cVar, com.ss.android.socialbase.downloader.e.a aVar) {
                d(cVar, -1);
            }
        }

        public void a(Message message) {
            if (message.what == 1) {
                com.bytedance.sdk.openadsdk.downloadnew.a.a.a aVar = y.i;
                if (aVar != null && aVar.a()) {
                    c.j.a.c.o.b.b.a.j("install_window_show", this.b);
                }
            }
        }

        /* JADX WARNING: Removed duplicated region for block: B:15:0x002b  */
        /* JADX WARNING: Removed duplicated region for block: B:19:0x0039  */
        public void b(com.ss.android.socialbase.downloader.g.c r7, c.j.a.a.a.e.e r8, java.util.List<c.j.a.a.a.c.e> r9) {
            /*
            r6 = this;
            r0 = r9.isEmpty();
            if (r0 == 0) goto L_0x0007;
        L_0x0006:
            return;
        L_0x0007:
            if (r7 == 0) goto L_0x0089;
        L_0x0009:
            if (r8 != 0) goto L_0x000d;
        L_0x000b:
            goto L_0x0089;
        L_0x000d:
            r0 = 0;
            r1 = r7.T;	 Catch:{ Exception -> 0x0023 }
            r3 = 0;
            r5 = (r1 > r3 ? 1 : (r1 == r3 ? 0 : -1));
            if (r5 <= 0) goto L_0x0027;
        L_0x0016:
            r1 = r7.I();	 Catch:{ Exception -> 0x0023 }
            r3 = 100;
            r1 = r1 * r3;
            r3 = r7.T;	 Catch:{ Exception -> 0x0023 }
            r1 = r1 / r3;
            r2 = (int) r1;
            goto L_0x0028;
        L_0x0023:
            r1 = move-exception;
            r1.printStackTrace();
        L_0x0027:
            r2 = 0;
        L_0x0028:
            if (r2 >= 0) goto L_0x002b;
        L_0x002a:
            goto L_0x002c;
        L_0x002b:
            r0 = r2;
        L_0x002c:
            r8.a(r7);
            r9 = r9.iterator();
        L_0x0033:
            r1 = r9.hasNext();
            if (r1 == 0) goto L_0x0088;
        L_0x0039:
            r1 = r9.next();
            r1 = (c.j.a.a.a.c.e) r1;
            r2 = r7.o0();
            switch(r2) {
                case -4: goto L_0x0073;
                case -3: goto L_0x0061;
                case -2: goto L_0x005d;
                case -1: goto L_0x0059;
                case 0: goto L_0x0073;
                case 1: goto L_0x0055;
                case 2: goto L_0x0055;
                case 3: goto L_0x0055;
                case 4: goto L_0x0055;
                case 5: goto L_0x0055;
                case 6: goto L_0x0046;
                case 7: goto L_0x0055;
                case 8: goto L_0x0055;
                case 9: goto L_0x0046;
                case 10: goto L_0x0046;
                case 11: goto L_0x0047;
                default: goto L_0x0046;
            };
        L_0x0046:
            goto L_0x0033;
        L_0x0047:
            r2 = r1 instanceof c.j.a.a.a.c.f;
            if (r2 == 0) goto L_0x0051;
        L_0x004b:
            r1 = (c.j.a.a.a.c.f) r1;
            r1.a(r7);
            goto L_0x0033;
        L_0x0051:
            r1.a(r8, r0);
            goto L_0x0033;
        L_0x0055:
            r1.a(r8, r0);
            goto L_0x0033;
        L_0x0059:
            r1.a(r8);
            goto L_0x0033;
        L_0x005d:
            r1.b(r8, r0);
            goto L_0x0033;
        L_0x0061:
            r2 = r6.b;
            r2 = r2.b;
            r2 = c.j.a.c.q.d.l(r2);
            if (r2 == 0) goto L_0x006f;
        L_0x006b:
            r1.b(r8);
            goto L_0x0033;
        L_0x006f:
            r1.c(r8);
            goto L_0x0033;
        L_0x0073:
            r2 = r6.b;
            r2 = r2.b;
            r2 = c.j.a.c.q.d.l(r2);
            if (r2 == 0) goto L_0x0084;
        L_0x007d:
            r2 = -3;
            r8.b = r2;
            r1.b(r8);
            goto L_0x0033;
        L_0x0084:
            r1.a();
            goto L_0x0033;
        L_0x0088:
            return;
        L_0x0089:
            r7 = r9.iterator();
        L_0x008d:
            r8 = r7.hasNext();
            if (r8 == 0) goto L_0x009d;
        L_0x0093:
            r8 = r7.next();
            r8 = (c.j.a.a.a.c.e) r8;
            r8.a();
            goto L_0x008d;
        L_0x009d:
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g$x.b(com.ss.android.socialbase.downloader.g.c, c.j.a.a.a.e.e, java.util.List):void");
        }

        public void c(com.ss.android.socialbase.downloader.g.c cVar) {
            if (c.h.a.m0.r.a.n(this.b.b) && !this.c) {
                int i;
                c.j.a.c.o.b bVar;
                c.j.a.c.g$g.d.b bVar2;
                if (cVar != null) {
                    String m0 = cVar.m0();
                    Object obj = null;
                    if (!TextUtils.isEmpty(m0) && new File(m0).exists()) {
                        obj = 1;
                    }
                    if (obj != null) {
                        i = 1;
                        bVar = c.j.a.c.o.b.b.a;
                        bVar2 = this.b;
                        bVar.l(bVar2.c.b(), "file_status", null, (long) i, 2, bVar2.b, bVar2.c);
                        this.c = true;
                    }
                }
                i = 2;
                bVar = c.j.a.c.o.b.b.a;
                bVar2 = this.b;
                bVar.l(bVar2.c.b(), "file_status", null, (long) i, 2, bVar2.b, bVar2.c);
                this.c = true;
            }
        }

        public void d(com.ss.android.socialbase.downloader.g.c cVar) {
            c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
            if (this.b.b != null && cVar != null && cVar.g0() != 0) {
                int o0 = cVar.o0();
                if (o0 == -1 || o0 == -4) {
                    bVar.c(this.a, 2);
                } else if (c.h.a.m0.r.a.n(this.b.b)) {
                    bVar.c(this.a, 2);
                }
                switch (o0) {
                    case BaseCode.NO_SOLUTION /*-4*/:
                    case -1:
                        if (this.e == null) {
                            this.e = new w(this);
                        }
                        c.j.a.c.g$g.d dVar = c.j.a.c.g$g.d.c.a;
                        c.j.a.c.g$g.d.b bVar2 = this.b;
                        dVar.e(new c.j.a.b.a.c.a(bVar2.b, bVar2.c, bVar2.d, cVar.g0()));
                        return;
                    case -3:
                        if (d.l(this.b.b)) {
                            d.n();
                            return;
                        }
                        bVar.d(this.a, 5, cVar);
                        Message obtain = Message.obtain();
                        obtain.what = 1;
                        this.d.sendMessageDelayed(obtain, 1200);
                        return;
                    case -2:
                        bVar.d(this.a, 4, cVar);
                        return;
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 7:
                    case 8:
                        bVar.d(this.a, 3, cVar);
                        return;
                    default:
                        return;
                }
            }
        }

        public static List<c.j.a.a.a.c.e> a(Map<Integer, Object> map) {
            ArrayList arrayList = new ArrayList();
            if (!(map == null || map.isEmpty())) {
                for (Object next : map.values()) {
                    if (next instanceof c.j.a.a.a.c.e) {
                        arrayList.add((c.j.a.a.a.c.e) next);
                    } else if (next instanceof SoftReference) {
                        SoftReference softReference = (SoftReference) next;
                        if (softReference.get() instanceof c.j.a.a.a.c.e) {
                            arrayList.add((c.j.a.a.a.c.e) softReference.get());
                        }
                    }
                }
            }
            return arrayList;
        }
    }

    /* compiled from: ReverseWifiHelper */
    public final class z implements c.j.a.c.g$d.d {
        public final /* synthetic */ int a;
        public final /* synthetic */ c.j.a.b.a.c.a b;

        public z(int i, c.j.a.b.a.c.a aVar) {
            this.a = i;
            this.b = aVar;
        }
    }

    public g() {
        c.j.a.d.a.g.a = this;
        c.j.a.d.b.a.a.c.a.a(this);
    }

    public static g d() {
        if (d == null) {
            synchronized (g.class) {
                if (d == null) {
                    d = new g();
                }
            }
        }
        return d;
    }

    public static com.ss.android.socialbase.downloader.g.c e(List<com.ss.android.socialbase.downloader.g.c> list, String str) {
        if (!(list.isEmpty() || TextUtils.isEmpty(str))) {
            for (com.ss.android.socialbase.downloader.g.c cVar : list) {
                if (cVar != null) {
                    if (str.equals(cVar.w)) {
                        return cVar;
                    }
                    String m0 = cVar.m0();
                    Context a = y.a();
                    int i = 0;
                    if (!(a == null || TextUtils.isEmpty(m0) || TextUtils.isEmpty(str))) {
                        try {
                            File file = new File(m0);
                            if (file.exists()) {
                                PackageInfo packageArchiveInfo = a.getPackageManager().getPackageArchiveInfo(file.getAbsolutePath(), 0);
                                if (packageArchiveInfo != null) {
                                    if (packageArchiveInfo.packageName.equals(str)) {
                                        PackageInfo packageInfo;
                                        int i2 = packageArchiveInfo.versionCode;
                                        try {
                                            packageInfo = a.getPackageManager().getPackageInfo(str, 0);
                                        } catch (NameNotFoundException unused) {
                                            packageInfo = null;
                                        }
                                        if (packageInfo != null) {
                                            if (i2 == packageInfo.versionCode) {
                                                i = 1;
                                            }
                                        }
                                    }
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if (i != 0) {
                        return cVar;
                    }
                }
            }
        }
        return null;
    }

    public static JSONObject g(JSONObject jSONObject, com.ss.android.socialbase.downloader.g.c cVar) {
        if (c.j.a.d.b.l.a.d(cVar.g0()).b("download_event_opt", 1) == 0) {
            return jSONObject;
        }
        try {
            long a = d.a(Environment.getExternalStorageDirectory());
            double d = (double) a;
            jSONObject.put("available_space", d / 1048576.0d);
            long j = cVar.T;
            double d2 = (double) j;
            jSONObject.put("apk_size", d2 / 1048576.0d);
            if (a > 0 && j > 0) {
                jSONObject.put("available_space_ratio", d / d2);
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        return jSONObject;
    }

    public static void i(g gVar, ConcurrentHashMap concurrentHashMap, int i) {
        Throwable th;
        g gVar2;
        Objects.requireNonNull(gVar);
        c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
        c.j.a.c.g$g.g gVar3 = c.j.a.c.g$g.g.b.a;
        ArrayList arrayList = new ArrayList();
        long currentTimeMillis = System.currentTimeMillis();
        Iterator it = concurrentHashMap.values().iterator();
        int i2 = i;
        while (true) {
            boolean z = true;
            if (!it.hasNext()) {
                break;
            }
            c.j.a.c.o.b bVar2;
            c.j.a.b.a.c.a aVar = (c.j.a.b.a.c.a) it.next();
            if (aVar.J.get()) {
                if (currentTimeMillis - aVar.o >= ((long) (((c.j.a.d.b.l.a.d(aVar.q).b("start_event_expire_hours", 168) * 60) * 60) * 1000))) {
                    arrayList.add(Long.valueOf(aVar.a));
                }
                bVar2 = bVar;
            } else {
                int i3 = aVar.d;
                com.ss.android.socialbase.downloader.g.c k;
                if (i3 == 1) {
                    c.j.a.c.o.b bVar3;
                    double a = c.j.a.d.b.l.a.d(aVar.q).a("download_failed_finally_hours", 48.0d);
                    if (a <= 0.0d) {
                        bVar3 = bVar;
                    } else {
                        bVar3 = bVar;
                        if (((double) (System.currentTimeMillis() - aVar.o)) >= ((a * 60.0d) * 60.0d) * 1000.0d) {
                            if (aVar.K.get()) {
                                bVar2 = bVar3;
                            } else {
                                k = c.j.a.d.b.e.i.a(y.a()).k(aVar.q);
                                if (k != null) {
                                    int p0 = k.p0();
                                    if (!(p0 == -3 || p0 == -4)) {
                                        if (!c.j.a.c.y.a.i.x(p0) && aVar.K.compareAndSet(false, true)) {
                                            try {
                                                JSONObject jSONObject = new JSONObject();
                                                n(jSONObject, k);
                                                jSONObject.putOpt("download_status", Integer.valueOf(p0));
                                                jSONObject.putOpt("fail_status", Integer.valueOf(aVar.y));
                                                jSONObject.putOpt("fail_msg", aVar.z);
                                                jSONObject.put("download_failed_times", aVar.s);
                                                if (k.T > 0) {
                                                    jSONObject.put("download_percent", ((double) k.I()) / ((double) k.T));
                                                }
                                                jSONObject.put("is_update_download", aVar.A ? 1 : 2);
                                                bVar2 = bVar3;
                                                try {
                                                    bVar2.q(aVar.D, "download_failed_finally", jSONObject, aVar);
                                                    gVar3.a(aVar);
                                                } catch (Throwable th2) {
                                                    th = th2;
                                                    th.printStackTrace();
                                                    arrayList.add(Long.valueOf(aVar.a));
                                                    gVar2 = gVar;
                                                    bVar = bVar2;
                                                }
                                            } catch (Throwable th3) {
                                                th = th3;
                                                bVar2 = bVar3;
                                                th.printStackTrace();
                                                arrayList.add(Long.valueOf(aVar.a));
                                                gVar2 = gVar;
                                                bVar = bVar2;
                                            }
                                        }
                                    }
                                }
                            }
                            z = false;
                            if (z > false && currentTimeMillis - aVar.o >= ((long) (((c.j.a.d.b.l.a.d(aVar.q).b("start_event_expire_hours", 168) * 60) * 60) * 1000))) {
                                arrayList.add(Long.valueOf(aVar.a));
                            }
                        }
                        bVar2 = bVar3;
                        arrayList.add(Long.valueOf(aVar.a));
                    }
                    bVar2 = bVar3;
                    z = true;
                    arrayList.add(Long.valueOf(aVar.a));
                } else {
                    bVar2 = bVar;
                    if (i3 != 2) {
                        gVar2 = gVar;
                        arrayList.add(Long.valueOf(aVar.a));
                    } else if (!aVar.M) {
                        if (d.o(aVar)) {
                            i3 = aVar.N;
                            if (i3 == 4) {
                                i2 = i3;
                            }
                            JSONObject f = gVar.f(aVar, aVar.e, i2);
                            String str = "hijack";
                            if (!(f.has(str) && f.optInt(str) == 1)) {
                                z = false;
                            }
                            c.j.a.c.y.a.i.p(z);
                            bVar2.q(aVar.D, "install_finish", f, aVar);
                            arrayList.add(Long.valueOf(aVar.a));
                            if (aVar.a > 0) {
                                k = c.j.a.d.b.e.i.a(y.a()).k(aVar.q);
                                if (k != null) {
                                    c.j.a.c.g$i.c.b(k);
                                }
                            }
                        } else {
                            gVar2 = gVar;
                            if (currentTimeMillis - aVar.o >= ((long) (((c.j.a.d.b.l.a.d(aVar.q).b("finish_event_expire_hours", 168) * 60) * 60) * 1000))) {
                                arrayList.add(Long.valueOf(aVar.a));
                            } else if (TextUtils.isEmpty(aVar.e)) {
                                arrayList.add(Long.valueOf(aVar.a));
                            }
                        }
                    }
                    bVar = bVar2;
                }
            }
            gVar2 = gVar;
            bVar = bVar2;
        }
        c.j.a.c.g$g.d dVar = c.j.a.c.g$g.d.c.a;
        synchronized (dVar) {
            ArrayList arrayList2 = new ArrayList();
            Iterator it2 = arrayList.iterator();
            while (it2.hasNext()) {
                currentTimeMillis = ((Long) it2.next()).longValue();
                arrayList2.add(String.valueOf(currentTimeMillis));
                dVar.e.remove(Long.valueOf(currentTimeMillis));
            }
            if (!arrayList2.isEmpty()) {
                c.j.a.c.o.a.a.b(new c.j.a.c.g$g.h(gVar3, arrayList2), true);
            }
        }
    }

    /* JADX WARNING: Missing block: B:39:0x00f6, code skipped:
            return;
     */
    public static synchronized void k(com.ss.android.socialbase.downloader.g.c r17, c.j.a.b.a.c.a r18) {
        /*
        r0 = r17;
        r1 = r18;
        r2 = c.j.a.c.o.a.a;
        r3 = c.j.a.c.g.class;
        monitor-enter(r3);
        r4 = r1.d;	 Catch:{ all -> 0x00f7 }
        r5 = 1;
        if (r4 == r5) goto L_0x0010;
    L_0x000e:
        monitor-exit(r3);
        return;
    L_0x0010:
        r4 = p(r17, r18);	 Catch:{ all -> 0x00f7 }
        r6 = c.j.a.c.g$g.d.c.a;	 Catch:{ all -> 0x00f7 }
        r7 = r0.d;	 Catch:{ all -> 0x00f7 }
        java.util.Objects.requireNonNull(r6);	 Catch:{ all -> 0x00f7 }
        r8 = android.text.TextUtils.isEmpty(r7);	 Catch:{ all -> 0x00f7 }
        if (r8 != 0) goto L_0x0051;
    L_0x0021:
        r8 = android.text.TextUtils.isEmpty(r4);	 Catch:{ all -> 0x00f7 }
        if (r8 == 0) goto L_0x0028;
    L_0x0027:
        goto L_0x0051;
    L_0x0028:
        r6 = r6.b;	 Catch:{ all -> 0x00f7 }
        r6 = r6.values();	 Catch:{ all -> 0x00f7 }
        r6 = r6.iterator();	 Catch:{ all -> 0x00f7 }
    L_0x0032:
        r8 = r6.hasNext();	 Catch:{ all -> 0x00f7 }
        if (r8 == 0) goto L_0x0051;
    L_0x0038:
        r8 = r6.next();	 Catch:{ all -> 0x00f7 }
        r8 = (c.j.a.a.a.c.d) r8;	 Catch:{ all -> 0x00f7 }
        r9 = r8 instanceof c.j.a.b.a.a.c;	 Catch:{ all -> 0x00f7 }
        if (r9 == 0) goto L_0x0032;
    L_0x0042:
        r9 = r8.a();	 Catch:{ all -> 0x00f7 }
        r9 = android.text.TextUtils.equals(r9, r7);	 Catch:{ all -> 0x00f7 }
        if (r9 == 0) goto L_0x0032;
    L_0x004c:
        r8 = (c.j.a.b.a.a.c) r8;	 Catch:{ all -> 0x00f7 }
        r8.f = r4;	 Catch:{ all -> 0x00f7 }
        goto L_0x0032;
    L_0x0051:
        r6 = c.j.a.c.g$g.d.c.a;	 Catch:{ all -> 0x00f7 }
        r7 = r0.d;	 Catch:{ all -> 0x00f7 }
        r6 = r6.d(r7, r4);	 Catch:{ all -> 0x00f7 }
        r7 = java.lang.System.currentTimeMillis();	 Catch:{ all -> 0x00f7 }
        r1.f(r7);	 Catch:{ all -> 0x00f7 }
        r7 = 2;
        r1.d = r7;	 Catch:{ all -> 0x00f7 }
        r1.e = r4;	 Catch:{ all -> 0x00f7 }
        r7 = r1.a;	 Catch:{ all -> 0x00f7 }
        r7 = java.lang.Long.valueOf(r7);	 Catch:{ all -> 0x00f7 }
        r6 = (java.util.HashMap) r6;
        r6.put(r7, r1);	 Catch:{ all -> 0x00f7 }
        r7 = c.j.a.c.g$g.g.b.a;	 Catch:{ all -> 0x00f7 }
        r6 = r6.values();	 Catch:{ all -> 0x00f7 }
        r7.b(r6);	 Catch:{ all -> 0x00f7 }
        o(r18);	 Catch:{ all -> 0x00f7 }
        r6 = c.j.a.c.x.b();	 Catch:{ all -> 0x00f7 }
        r7 = r6.a;	 Catch:{ all -> 0x00f7 }
        r8 = new c.j.a.c.u;	 Catch:{ all -> 0x00f7 }
        r8.m2312init(r6, r0, r4);	 Catch:{ all -> 0x00f7 }
        r7.post(r8);	 Catch:{ all -> 0x00f7 }
        r6 = "application/vnd.android.package-archive";
        r7 = r0.u;	 Catch:{ all -> 0x00f7 }
        r6 = r6.equals(r7);	 Catch:{ all -> 0x00f7 }
        if (r6 == 0) goto L_0x00f5;
    L_0x0094:
        r6 = d();	 Catch:{ all -> 0x00f7 }
        java.util.Objects.requireNonNull(r6);	 Catch:{ all -> 0x00f7 }
        r7 = new c.j.a.c.g$c;	 Catch:{ all -> 0x00f7 }
        r7.m2256init(r1);	 Catch:{ all -> 0x00f7 }
        r6 = 0;
        r2.b(r7, r6);	 Catch:{ all -> 0x00f7 }
        r6 = d();	 Catch:{ all -> 0x00f7 }
        java.util.Objects.requireNonNull(r6);	 Catch:{ all -> 0x00f7 }
        r7 = r17.g0();	 Catch:{ all -> 0x00f7 }
        r7 = c.j.a.d.b.l.a.d(r7);	 Catch:{ all -> 0x00f7 }
        r8 = "install_finish_check_ttmd5";
        r5 = r7.b(r8, r5);	 Catch:{ all -> 0x00f7 }
        if (r5 != 0) goto L_0x00bc;
    L_0x00bb:
        goto L_0x00cf;
    L_0x00bc:
        r5 = r17.m0();	 Catch:{ all -> 0x00f7 }
        r7 = android.text.TextUtils.isEmpty(r5);	 Catch:{ all -> 0x00f7 }
        if (r7 == 0) goto L_0x00c7;
    L_0x00c6:
        goto L_0x00cf;
    L_0x00c7:
        r7 = new c.j.a.c.f;	 Catch:{ all -> 0x00f7 }
        r7.m2253init(r6, r5, r1);	 Catch:{ all -> 0x00f7 }
        r2.c(r7);	 Catch:{ all -> 0x00f7 }
    L_0x00cf:
        r2 = r1.r;	 Catch:{ all -> 0x00f7 }
        if (r2 == 0) goto L_0x00ee;
    L_0x00d3:
        r6 = c.j.a.c.g$d.b.a();	 Catch:{ all -> 0x00f7 }
        r2 = r17.g0();	 Catch:{ all -> 0x00f7 }
        r7 = (long) r2;	 Catch:{ all -> 0x00f7 }
        r9 = r1.a;	 Catch:{ all -> 0x00f7 }
        r11 = r1.b;	 Catch:{ all -> 0x00f7 }
        r14 = r17.j0();	 Catch:{ all -> 0x00f7 }
        r15 = r1.c;	 Catch:{ all -> 0x00f7 }
        r16 = r17.m0();	 Catch:{ all -> 0x00f7 }
        r13 = r4;
        r6.c(r7, r9, r11, r13, r14, r15, r16);	 Catch:{ all -> 0x00f7 }
    L_0x00ee:
        r5 = r1.a;	 Catch:{ all -> 0x00f7 }
        r1 = r1.c;	 Catch:{ all -> 0x00f7 }
        c.h.a.m0.r.a.i(r0, r5, r1, r4);	 Catch:{ all -> 0x00f7 }
    L_0x00f5:
        monitor-exit(r3);
        return;
    L_0x00f7:
        r0 = move-exception;
        monitor-exit(r3);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g.k(com.ss.android.socialbase.downloader.g.c, c.j.a.b.a.c.a):void");
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:57:0x0197 */
    /* JADX WARNING: Can't wrap try/catch for region: R(5:54|55|56|57|58) */
    public static org.json.JSONObject n(org.json.JSONObject r10, com.ss.android.socialbase.downloader.g.c r11) {
        /*
        r0 = "rw_concurrent";
        r1 = "retry_schedule_count";
        if (r11 != 0) goto L_0x0008;
    L_0x0006:
        goto L_0x024b;
    L_0x0008:
        r2 = r11.g0();
        r2 = c.j.a.d.b.l.a.d(r2);
        r3 = "download_event_opt";
        r4 = 1;
        r2 = r2.b(r3, r4);
        if (r2 != 0) goto L_0x001a;
    L_0x0019:
        return r10;
    L_0x001a:
        r2 = "download_id";
        r3 = r11.g0();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "name";
        r3 = r11.b;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "url";
        r3 = r11.d;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "cur_bytes";
        r5 = r11.I();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r5);	 Catch:{ all -> 0x0247 }
        r2 = "total_bytes";
        r5 = r11.T;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r5);	 Catch:{ all -> 0x0247 }
        r2 = "network_quality";
        r3 = r11.O;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = c.j.a.d.b.i.k.b.a;	 Catch:{ all -> 0x0247 }
        r2 = r2.b();	 Catch:{ all -> 0x0247 }
        r3 = "current_network_quality";
        r2 = r2.name();	 Catch:{ all -> 0x0247 }
        r10.put(r3, r2);	 Catch:{ all -> 0x0247 }
        r2 = "only_wifi";
        r3 = r11.g;	 Catch:{ all -> 0x0247 }
        r5 = 0;
        if (r3 == 0) goto L_0x0060;
    L_0x005e:
        r3 = 1;
        goto L_0x0061;
    L_0x0060:
        r3 = 0;
    L_0x0061:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "need_https_degrade";
        r3 = r11.v;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x006c;
    L_0x006a:
        r3 = 1;
        goto L_0x006d;
    L_0x006c:
        r3 = 0;
    L_0x006d:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "https_degrade_retry_used";
        r3 = r11.b0;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x0078;
    L_0x0076:
        r3 = 1;
        goto L_0x0079;
    L_0x0078:
        r3 = 0;
    L_0x0079:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "chunk_count";
        r3 = r11.R;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "retry_count";
        r3 = r11.m;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "cur_retry_time";
        r3 = r11.F;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "need_retry_delay";
        r3 = r11.A;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x0099;
    L_0x0097:
        r3 = 1;
        goto L_0x009a;
    L_0x0099:
        r3 = 0;
    L_0x009a:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "backup_url_used";
        r3 = r11.Z;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x00a5;
    L_0x00a3:
        r3 = 1;
        goto L_0x00a6;
    L_0x00a5:
        r3 = 0;
    L_0x00a6:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "head_connection_error_msg";
        r3 = r11.m0;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x00b0;
    L_0x00af:
        goto L_0x00b2;
    L_0x00b0:
        r3 = "";
    L_0x00b2:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "need_independent_process";
        r3 = r11.K;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x00bd;
    L_0x00bb:
        r3 = 1;
        goto L_0x00be;
    L_0x00bd:
        r3 = 0;
    L_0x00be:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "total_retry_count";
        r3 = r11.d();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "cur_retry_time_in_total";
        r3 = r11.e();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "real_download_time";
        r6 = r11.A();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r6);	 Catch:{ all -> 0x0247 }
        r2 = "first_speed_time";
        r11.M();	 Catch:{ all -> 0x0247 }
        r3 = r11.D0;	 Catch:{ all -> 0x0247 }
        r6 = "dbjson_key_first_speed_time";
        r6 = r3.optLong(r6);	 Catch:{ all -> 0x0247 }
        r10.put(r2, r6);	 Catch:{ all -> 0x0247 }
        r2 = "all_connect_time";
        r6 = r11.a();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r6);	 Catch:{ all -> 0x0247 }
        r2 = "download_prepare_time";
        r6 = r11.b();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r6);	 Catch:{ all -> 0x0247 }
        r2 = "download_time";
        r6 = r11.A();	 Catch:{ all -> 0x0247 }
        r8 = r11.a();	 Catch:{ all -> 0x0247 }
        r6 = r6 + r8;
        r8 = r11.b();	 Catch:{ all -> 0x0247 }
        r6 = r6 + r8;
        r10.put(r2, r6);	 Catch:{ all -> 0x0247 }
        r2 = "chunk_downgrade_retry_used";
        r3 = r11.y0;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x0119;
    L_0x0117:
        r3 = 1;
        goto L_0x011a;
    L_0x0119:
        r3 = 0;
    L_0x011a:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "need_chunk_downgrade_retry";
        r3 = r11.x0;	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x0125;
    L_0x0123:
        r3 = 1;
        goto L_0x0126;
    L_0x0125:
        r3 = 0;
    L_0x0126:
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "failed_resume_count";
        r3 = r11.V();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r11.M();	 Catch:{ all -> 0x0247 }
        r2 = r11.D0;	 Catch:{ all -> 0x0247 }
        r3 = "dbjson_key_preconnect_level";
        r2 = r2.optInt(r3, r5);	 Catch:{ all -> 0x0247 }
        r3 = "preconnect_level";
        r10.put(r3, r2);	 Catch:{ all -> 0x0247 }
        r2 = "md5";
        r3 = r11.y;	 Catch:{ all -> 0x0247 }
        r10.put(r2, r3);	 Catch:{ all -> 0x0247 }
        r2 = "expect_file_length";
        r6 = r11.c();	 Catch:{ all -> 0x0247 }
        r10.put(r2, r6);	 Catch:{ all -> 0x0247 }
        r11.M();	 Catch:{ all -> 0x0247 }
        r2 = r11.D0;	 Catch:{ all -> 0x0247 }
        r2 = r2.optInt(r1, r5);	 Catch:{ all -> 0x0247 }
        r10.put(r1, r2);	 Catch:{ all -> 0x0247 }
        r11.M();	 Catch:{ all -> 0x0247 }
        r1 = r11.D0;	 Catch:{ all -> 0x0247 }
        r1 = r1.optInt(r0, r5);	 Catch:{ all -> 0x0247 }
        if (r1 != r4) goto L_0x016b;
    L_0x0169:
        r1 = 1;
        goto L_0x016c;
    L_0x016b:
        r1 = 0;
    L_0x016c:
        if (r1 == 0) goto L_0x0170;
    L_0x016e:
        r1 = 1;
        goto L_0x0171;
    L_0x0170:
        r1 = 0;
    L_0x0171:
        r10.put(r0, r1);	 Catch:{ all -> 0x0247 }
        r0 = r11.I();	 Catch:{ all -> 0x0247 }
        r0 = (double) r0;	 Catch:{ all -> 0x0247 }
        r2 = 4697254411347427328; // 0x4130000000000000 float:0.0 double:1048576.0;
        r0 = r0 / r2;
        r2 = r11.A();	 Catch:{ all -> 0x0247 }
        r2 = (double) r2;
        r6 = 4652007308841189376; // 0x408f400000000000 float:0.0 double:1000.0;
        r2 = r2 / r6;
        r6 = 0;
        r8 = (r0 > r6 ? 1 : (r0 == r6 ? 0 : -1));
        if (r8 <= 0) goto L_0x01b2;
    L_0x018d:
        r8 = (r2 > r6 ? 1 : (r2 == r6 ? 0 : -1));
        if (r8 <= 0) goto L_0x01b2;
    L_0x0191:
        r0 = r0 / r2;
        r2 = "download_speed";
        r10.put(r2, r0);	 Catch:{ Exception -> 0x0197 }
    L_0x0197:
        r2 = c;	 Catch:{ all -> 0x0247 }
        r3 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0247 }
        r3.<init>();	 Catch:{ all -> 0x0247 }
        r6 = "download speed : ";
        r3.append(r6);	 Catch:{ all -> 0x0247 }
        r3.append(r0);	 Catch:{ all -> 0x0247 }
        r0 = "MB/s";
        r3.append(r0);	 Catch:{ all -> 0x0247 }
        r0 = r3.toString();	 Catch:{ all -> 0x0247 }
        c.j.a.d.b.g.a.d(r2, r0);	 Catch:{ all -> 0x0247 }
    L_0x01b2:
        r0 = c.j.a.c.g.y.a();	 Catch:{ Exception -> 0x01d8 }
        r0 = c.j.a.d.b.e.i.a(r0);	 Catch:{ Exception -> 0x01d8 }
        r1 = r11.g0();	 Catch:{ Exception -> 0x01d8 }
        java.util.Objects.requireNonNull(r0);	 Catch:{ Exception -> 0x01d8 }
        r0 = c.j.a.d.b.e.d.b();	 Catch:{ Exception -> 0x01d8 }
        r0 = r0.h(r1);	 Catch:{ Exception -> 0x01d8 }
        r0 = r0.b();	 Catch:{ Exception -> 0x01d8 }
        r1 = "is_download_service_foreground";
        if (r0 == 0) goto L_0x01d3;
    L_0x01d1:
        r0 = 1;
        goto L_0x01d4;
    L_0x01d3:
        r0 = 0;
    L_0x01d4:
        r10.put(r1, r0);	 Catch:{ Exception -> 0x01d8 }
        goto L_0x01dc;
    L_0x01d8:
        r0 = move-exception;
        r0.printStackTrace();	 Catch:{ all -> 0x0247 }
    L_0x01dc:
        r0 = r11.s;	 Catch:{ all -> 0x0247 }
        if (r0 == 0) goto L_0x01f0;
    L_0x01e0:
        r1 = "backup_url_count";
        r0 = r0.size();	 Catch:{ all -> 0x0247 }
        r10.put(r1, r0);	 Catch:{ all -> 0x0247 }
        r0 = "cur_backup_url_index";
        r1 = r11.P;	 Catch:{ all -> 0x0247 }
        r10.put(r0, r1);	 Catch:{ all -> 0x0247 }
    L_0x01f0:
        r0 = "clear_space_restart_times";
        r1 = c.j.a.c.g$i.c.a();	 Catch:{ all -> 0x0247 }
        r2 = r11.d;	 Catch:{ all -> 0x0247 }
        java.util.Objects.requireNonNull(r1);	 Catch:{ all -> 0x0247 }
        r3 = android.text.TextUtils.isEmpty(r2);	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x0202;
    L_0x0201:
        goto L_0x0221;
    L_0x0202:
        r3 = r1.c;	 Catch:{ all -> 0x0247 }
        if (r3 != 0) goto L_0x020d;
    L_0x0206:
        r3 = new java.util.HashMap;	 Catch:{ all -> 0x0247 }
        r3.<init>();	 Catch:{ all -> 0x0247 }
        r1.c = r3;	 Catch:{ all -> 0x0247 }
    L_0x020d:
        r3 = r1.c;	 Catch:{ all -> 0x0247 }
        r3 = r3.containsKey(r2);	 Catch:{ all -> 0x0247 }
        if (r3 == 0) goto L_0x0221;
    L_0x0215:
        r1 = r1.c;	 Catch:{ all -> 0x0247 }
        r1 = r1.get(r2);	 Catch:{ all -> 0x0247 }
        r1 = (java.lang.Integer) r1;	 Catch:{ all -> 0x0247 }
        r5 = r1.intValue();	 Catch:{ all -> 0x0247 }
    L_0x0221:
        r10.put(r0, r5);	 Catch:{ all -> 0x0247 }
        r0 = "mime_type";
        r1 = r11.u;	 Catch:{ all -> 0x0247 }
        r10.put(r0, r1);	 Catch:{ all -> 0x0247 }
        r0 = "network_available";
        r1 = c.j.a.c.g.y.a();	 Catch:{ all -> 0x0247 }
        r1 = c.j.a.d.b.n.a.G(r1);	 Catch:{ all -> 0x0247 }
        if (r1 == 0) goto L_0x0238;
    L_0x0237:
        goto L_0x0239;
    L_0x0238:
        r4 = 2;
    L_0x0239:
        r10.put(r0, r4);	 Catch:{ all -> 0x0247 }
        r0 = "status_code";
        r1 = r11.n0;	 Catch:{ all -> 0x0247 }
        r10.put(r0, r1);	 Catch:{ all -> 0x0247 }
        g(r10, r11);	 Catch:{ all -> 0x0247 }
        goto L_0x024b;
    L_0x0247:
        r11 = move-exception;
        r11.printStackTrace();
    L_0x024b:
        return r10;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g.n(org.json.JSONObject, com.ss.android.socialbase.downloader.g.c):org.json.JSONObject");
    }

    public static void o(c.j.a.b.a.c.a aVar) {
        Object obj;
        String str = "";
        if (TextUtils.isEmpty(aVar.H)) {
            obj = str;
        } else {
            obj = aVar.H;
        }
        com.ss.android.socialbase.downloader.g.c k = c.j.a.d.b.e.i.a(y.a()).k(aVar.q);
        aVar.H = str;
        c.j.a.c.g$g.g.b.a.a(aVar);
        JSONObject n = n(new JSONObject(), k);
        int i = 1;
        try {
            n.putOpt("finish_reason", obj);
            n.putOpt("finish_from_reserve_wifi", Integer.valueOf(k.G0 ? 1 : 0));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        c.j.a.b.a.c.a b = c.j.a.c.g$g.d.c.a.b(k);
        y.f(n, k.g0());
        try {
            n.put("download_failed_times", b.s);
            n.put("can_show_notification", c.j.a.d.a.j.e.a() ? 1 : 2);
            if (k.c() > 0 && k.T > 0) {
                n.put("file_length_gap", k.c() - k.T);
            }
            k.M();
            n.put("ttmd5_status", k.D0.optInt("ttmd5_check_status", -1));
            n.put("has_send_download_failed_finally", b.K.get() ? 1 : 2);
            String str2 = "is_update_download";
            if (!b.A) {
                i = 2;
            }
            n.put(str2, i);
            y.e(b, n);
        } catch (Throwable th) {
            th.printStackTrace();
        }
        c.j.a.c.o.b.b.a.q(aVar.D, "download_finish", n, aVar);
    }

    public static String p(com.ss.android.socialbase.downloader.g.c cVar, c.j.a.b.a.c.a aVar) {
        CharSequence charSequence;
        File file = new File(cVar.e, cVar.b);
        if (file.exists()) {
            try {
                PackageInfo packageArchiveInfo = y.a().getPackageManager().getPackageArchiveInfo(file.getAbsolutePath(), c.j.a.d.a.h.a());
                if (packageArchiveInfo != null) {
                    charSequence = packageArchiveInfo.packageName;
                    if (!TextUtils.isEmpty(charSequence) || charSequence.equals(cVar.w)) {
                        return cVar.w;
                    }
                    JSONObject jSONObject = new JSONObject();
                    try {
                        jSONObject.put("real_package_name", charSequence);
                        jSONObject.put("input_package_name", cVar.w);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    c.j.a.c.o.b.b.a.q("embeded_ad", "package_name_error", jSONObject, aVar);
                    return charSequence;
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        charSequence = null;
        if (!TextUtils.isEmpty(charSequence)) {
        }
        return cVar.w;
    }

    /* JADX WARNING: Removed duplicated region for block: B:34:0x0066  */
    /* JADX WARNING: Removed duplicated region for block: B:22:0x0045 A:{Catch:{ NameNotFoundException -> 0x0048 }} */
    /* JADX WARNING: Removed duplicated region for block: B:26:0x004b A:{SKIP} */
    /* JADX WARNING: Removed duplicated region for block: B:34:0x0066  */
    public final int a(c.j.a.b.a.c.a r6, com.ss.android.socialbase.downloader.g.c r7, java.lang.String r8, org.json.JSONObject r9) {
        /*
        r5 = this;
        r0 = c.j.a.c.g.y.a();
        r1 = 0;
        if (r0 == 0) goto L_0x002e;
    L_0x0007:
        if (r7 == 0) goto L_0x002e;
    L_0x0009:
        r2 = r7.e;
        r2 = android.text.TextUtils.isEmpty(r2);
        if (r2 != 0) goto L_0x002e;
    L_0x0011:
        r2 = r7.b;
        r2 = android.text.TextUtils.isEmpty(r2);
        if (r2 == 0) goto L_0x001a;
    L_0x0019:
        goto L_0x002e;
    L_0x001a:
        r2 = r7.t0;
        if (r2 <= 0) goto L_0x001f;
    L_0x001e:
        goto L_0x002f;
    L_0x001f:
        r2 = r7.e;	 Catch:{ all -> 0x002e }
        r3 = r7.b;	 Catch:{ all -> 0x002e }
        r0 = c.j.a.d.a.h.e(r0, r2, r3);	 Catch:{ all -> 0x002e }
        if (r0 == 0) goto L_0x002e;
    L_0x0029:
        r2 = r0.versionCode;	 Catch:{ all -> 0x002e }
        r7.t0 = r2;	 Catch:{ all -> 0x002e }
        goto L_0x002f;
    L_0x002e:
        r2 = 0;
    L_0x002f:
        r0 = c.j.a.c.g.y.a();
        if (r0 == 0) goto L_0x0048;
    L_0x0035:
        r3 = android.text.TextUtils.isEmpty(r8);
        if (r3 != 0) goto L_0x0048;
    L_0x003b:
        r0 = r0.getPackageManager();	 Catch:{ NameNotFoundException -> 0x0048 }
        r0 = r0.getPackageInfo(r8, r1);	 Catch:{ NameNotFoundException -> 0x0048 }
        if (r0 == 0) goto L_0x0048;
    L_0x0045:
        r0 = r0.versionCode;	 Catch:{ NameNotFoundException -> 0x0048 }
        goto L_0x0049;
    L_0x0048:
        r0 = -1;
    L_0x0049:
        if (r2 <= 0) goto L_0x0057;
    L_0x004b:
        if (r0 <= 0) goto L_0x0057;
    L_0x004d:
        if (r2 == r0) goto L_0x0057;
    L_0x004f:
        if (r0 <= r2) goto L_0x0054;
    L_0x0051:
        r6 = 3011; // 0xbc3 float:4.22E-42 double:1.4876E-320;
        goto L_0x0056;
    L_0x0054:
        r6 = 3010; // 0xbc2 float:4.218E-42 double:1.487E-320;
    L_0x0056:
        return r6;
    L_0x0057:
        r0 = r6.q;
        r0 = c.j.a.d.b.l.a.d(r0);
        r2 = 1;
        r3 = "install_finish_check_ttmd5";
        r0 = r0.b(r3, r2);
        if (r0 != r2) goto L_0x00c6;
    L_0x0066:
        r0 = c.j.a.c.g.y.a();
        r3 = "sp_ttdownloader_md5";
        r0 = r0.getSharedPreferences(r3, r1);
        r3 = r6.a;
        r6 = java.lang.String.valueOf(r3);
        r3 = 0;
        r6 = r0.getString(r6, r3);
        r0 = android.text.TextUtils.isEmpty(r6);
        if (r0 == 0) goto L_0x008b;
    L_0x0081:
        if (r7 == 0) goto L_0x008b;
    L_0x0083:
        r6 = r7.m0();
        r6 = c.j.a.c.g.y.c(r6);
    L_0x008b:
        r7 = android.text.TextUtils.isEmpty(r8);
        if (r7 == 0) goto L_0x0092;
    L_0x0091:
        goto L_0x00a4;
    L_0x0092:
        r7 = c.j.a.c.g.y.a();	 Catch:{ Exception -> 0x00a3 }
        r7 = r7.getPackageManager();	 Catch:{ Exception -> 0x00a3 }
        r7 = r7.getApplicationInfo(r8, r1);	 Catch:{ Exception -> 0x00a3 }
        if (r7 == 0) goto L_0x00a4;
    L_0x00a0:
        r3 = r7.sourceDir;	 Catch:{ Exception -> 0x00a3 }
        goto L_0x00a4;
    L_0x00a4:
        r7 = android.text.TextUtils.isEmpty(r3);
        if (r7 == 0) goto L_0x00ac;
    L_0x00aa:
        r6 = 5;
        goto L_0x00b5;
    L_0x00ac:
        r7 = new java.io.File;
        r7.<init>(r3);
        r6 = c.j.a.e.b.b(r6, r7);
    L_0x00b5:
        r7 = "ttmd5_status";
        r9.put(r7, r6);	 Catch:{ all -> 0x00bb }
        goto L_0x00bc;
    L_0x00bc:
        if (r6 != 0) goto L_0x00c1;
    L_0x00be:
        r6 = 3000; // 0xbb8 float:4.204E-42 double:1.482E-320;
        return r6;
    L_0x00c1:
        if (r6 != r2) goto L_0x00c6;
    L_0x00c3:
        r6 = 3002; // 0xbba float:4.207E-42 double:1.483E-320;
        return r6;
    L_0x00c6:
        r6 = 3001; // 0xbb9 float:4.205E-42 double:1.4827E-320;
        return r6;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g.a(c.j.a.b.a.c.a, com.ss.android.socialbase.downloader.g.c, java.lang.String, org.json.JSONObject):int");
    }

    public void b() {
        q();
        h(5);
    }

    public void c() {
        h(6);
    }

    /* JADX WARNING: Removed duplicated region for block: B:15:0x0061 A:{Catch:{ all -> 0x008a }} */
    /* JADX WARNING: Missing exception handler attribute for start block: B:12:0x0051 */
    /* JADX WARNING: Can't wrap try/catch for region: R(6:8|9|(1:11)|12|13|(2:15|(1:17))) */
    public final org.json.JSONObject f(c.j.a.b.a.c.a r10, java.lang.String r11, int r12) {
        /*
        r9 = this;
        r0 = new org.json.JSONObject;
        r0.<init>();
        r1 = c.j.a.c.g.y.a();	 Catch:{ all -> 0x008a }
        r1 = c.j.a.d.b.e.i.a(r1);	 Catch:{ all -> 0x008a }
        r2 = r10.q;	 Catch:{ all -> 0x008a }
        r1 = r1.k(r2);	 Catch:{ all -> 0x008a }
        r2 = "scene";
        r12 = java.lang.Integer.valueOf(r12);	 Catch:{ all -> 0x008a }
        r0.putOpt(r2, r12);	 Catch:{ all -> 0x008a }
        r12 = r10.q;	 Catch:{ all -> 0x008a }
        c.j.a.c.g.y.f(r0, r12);	 Catch:{ all -> 0x008a }
        c.j.a.c.g.y.e(r10, r0);	 Catch:{ all -> 0x008a }
        r12 = "is_update_download";
        r2 = r10.A;	 Catch:{ all -> 0x008a }
        r3 = 2;
        r4 = 1;
        if (r2 == 0) goto L_0x002e;
    L_0x002c:
        r2 = 1;
        goto L_0x002f;
    L_0x002e:
        r2 = 2;
    L_0x002f:
        r0.put(r12, r2);	 Catch:{ all -> 0x008a }
        if (r1 == 0) goto L_0x006a;
    L_0x0034:
        r12 = "uninstall_resume_count";
        r2 = r1.W();	 Catch:{ all -> 0x0051 }
        r0.put(r12, r2);	 Catch:{ all -> 0x0051 }
        r5 = r10.v;	 Catch:{ all -> 0x0051 }
        r7 = 0;
        r12 = (r5 > r7 ? 1 : (r5 == r7 ? 0 : -1));
        if (r12 <= 0) goto L_0x0051;
    L_0x0045:
        r12 = "install_time";
        r5 = java.lang.System.currentTimeMillis();	 Catch:{ all -> 0x0051 }
        r7 = r10.v;	 Catch:{ all -> 0x0051 }
        r5 = r5 - r7;
        r0.put(r12, r5);	 Catch:{ all -> 0x0051 }
    L_0x0051:
        r12 = r1.Y();	 Catch:{ all -> 0x008a }
        r2 = "anti_hijack_attempt";
        r12 = r12.getString(r2);	 Catch:{ all -> 0x008a }
        r2 = android.text.TextUtils.isEmpty(r12);	 Catch:{ all -> 0x008a }
        if (r2 != 0) goto L_0x006a;
    L_0x0061:
        r12 = c.j.a.d.a.d.a(r12);	 Catch:{ all -> 0x008a }
        if (r12 == 0) goto L_0x006a;
    L_0x0067:
        r12.b(r0);	 Catch:{ all -> 0x008a }
    L_0x006a:
        r10 = r9.a(r10, r1, r11, r0);	 Catch:{ all -> 0x008a }
        r11 = "fail_status";
        r0.put(r11, r10);	 Catch:{ all -> 0x008a }
        r11 = 3000; // 0xbb8 float:4.204E-42 double:1.482E-320;
        r12 = "hijack";
        if (r10 != r11) goto L_0x007d;
    L_0x0079:
        r0.put(r12, r3);	 Catch:{ all -> 0x008a }
        goto L_0x008e;
    L_0x007d:
        r11 = 3001; // 0xbb9 float:4.205E-42 double:1.4827E-320;
        if (r10 != r11) goto L_0x0086;
    L_0x0081:
        r10 = 0;
        r0.put(r12, r10);	 Catch:{ all -> 0x008a }
        goto L_0x008e;
    L_0x0086:
        r0.put(r12, r4);	 Catch:{ all -> 0x008a }
        goto L_0x008e;
    L_0x008a:
        r10 = move-exception;
        r10.printStackTrace();
    L_0x008e:
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g.f(c.j.a.b.a.c.a, java.lang.String, int):org.json.JSONObject");
    }

    public void h(int i) {
        long currentTimeMillis = System.currentTimeMillis();
        long j = this.a;
        if (currentTimeMillis - j >= 120000) {
            c.j.a.c.o.a.a.a(new a(i), j > 0 ? 2000 : 8000);
            this.a = currentTimeMillis;
        }
    }

    public void j(com.ss.android.socialbase.downloader.g.c cVar, long j, long j2, long j3, long j4, long j5, boolean z) {
        com.ss.android.socialbase.downloader.g.c cVar2 = cVar;
        long j6 = j;
        c.j.a.c.o.b bVar = c.j.a.c.o.b.b.a;
        c.j.a.b.a.c.a b = c.j.a.c.g$g.d.c.a.b(cVar);
        if (b == null) {
            d.n();
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.putOpt("space_before", Double.valueOf(((double) j6) / 1048576.0d));
            jSONObject.putOpt("space_cleaned", Double.valueOf(((double) (j2 - j6)) / 1048576.0d));
            jSONObject.putOpt("clean_up_time_cost", Long.valueOf(j4));
            jSONObject.putOpt("is_download_restarted", Integer.valueOf(z ? 1 : 0));
            jSONObject.putOpt("byte_required", Long.valueOf(j3));
            jSONObject.putOpt("clear_sleep_time", Long.valueOf(j5));
            bVar.f(cVar, jSONObject);
            bVar.q("embeded_ad", "cleanup", jSONObject, b);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void l(com.ss.android.socialbase.downloader.g.c cVar, c.j.a.b.a.c.a aVar, int i) {
        long j;
        q();
        long currentTimeMillis = System.currentTimeMillis();
        aVar.v = currentTimeMillis;
        aVar.L = d.a(Environment.getDataDirectory());
        if (i != 2000) {
            j = 2000;
        } else {
            j = c.j.a.d.b.l.a.d(cVar.g0()).c("check_install_failed_delay_time", 120000);
            if (j >= 0) {
                j = Math.max(j, 30000);
            } else {
                return;
            }
        }
        long j2 = j;
        b bVar = new b(aVar.a, cVar.g0(), currentTimeMillis, i, null);
        c.j.a.c.o.a.a.a(bVar, j2);
        this.b = bVar;
        c.j.a.c.g$g.g.b.a.a(aVar);
    }

    /* JADX WARNING: Missing block: B:46:0x00d6, code skipped:
            return;
     */
    public synchronized void m(java.lang.String r9) {
        /*
        r8 = this;
        monitor-enter(r8);
        r0 = android.text.TextUtils.isEmpty(r9);	 Catch:{ all -> 0x00df }
        if (r0 == 0) goto L_0x0009;
    L_0x0007:
        monitor-exit(r8);
        return;
    L_0x0009:
        r0 = c.j.a.c.q.d.k();	 Catch:{ all -> 0x00df }
        if (r0 != 0) goto L_0x00d7;
    L_0x000f:
        r0 = c.j.a.c.g$g.d.c.a;	 Catch:{ all -> 0x00df }
        r0 = r0.c(r9);	 Catch:{ all -> 0x00df }
        if (r0 != 0) goto L_0x0020;
    L_0x0017:
        r0 = c.j.a.c.g$g.c.b();	 Catch:{ all -> 0x00df }
        r0.c(r9);	 Catch:{ all -> 0x00df }
        monitor-exit(r8);
        return;
    L_0x0020:
        r1 = c.j.a.c.x.b();	 Catch:{ all -> 0x00df }
        r2 = r0.f;	 Catch:{ all -> 0x00df }
        r1 = r1.a(r2);	 Catch:{ all -> 0x00df }
        if (r1 == 0) goto L_0x0036;
    L_0x002c:
        r2 = r1.a;	 Catch:{ all -> 0x00df }
        r3 = new c.j.a.c.g$r;	 Catch:{ all -> 0x00df }
        r3.m2290init(r1);	 Catch:{ all -> 0x00df }
        r2.post(r3);	 Catch:{ all -> 0x00df }
    L_0x0036:
        r1 = r0.J;	 Catch:{ all -> 0x00df }
        r1 = r1.get();	 Catch:{ all -> 0x00df }
        if (r1 == 0) goto L_0x0040;
    L_0x003e:
        monitor-exit(r8);
        return;
    L_0x0040:
        r1 = c.j.a.c.q.d.o(r0);	 Catch:{ all -> 0x00df }
        r2 = 1;
        r3 = 0;
        r4 = 4;
        if (r1 != 0) goto L_0x004a;
    L_0x0049:
        goto L_0x006b;
    L_0x004a:
        r1 = r0.J;	 Catch:{ all -> 0x00df }
        r1 = r1.compareAndSet(r3, r2);	 Catch:{ all -> 0x00df }
        if (r1 == 0) goto L_0x006b;
    L_0x0052:
        r1 = r0.N;	 Catch:{ all -> 0x00df }
        if (r1 != r4) goto L_0x0058;
    L_0x0056:
        r1 = 4;
        goto L_0x0059;
    L_0x0058:
        r1 = 3;
    L_0x0059:
        r1 = r8.f(r0, r9, r1);	 Catch:{ all -> 0x00df }
        r5 = c.j.a.c.o.b.b.a;	 Catch:{ all -> 0x00df }
        r6 = r0.D;	 Catch:{ all -> 0x00df }
        r7 = "install_finish";
        r5.q(r6, r7, r1, r0);	 Catch:{ all -> 0x00df }
        r1 = c.j.a.c.g$g.g.b.a;	 Catch:{ all -> 0x00df }
        r1.a(r0);	 Catch:{ all -> 0x00df }
    L_0x006b:
        r1 = c.j.a.c.g.y.k(r9, r0);	 Catch:{ all -> 0x00df }
        if (r1 != 0) goto L_0x007e;
    L_0x0071:
        r1 = r0.N;	 Catch:{ all -> 0x00df }
        if (r1 != r4) goto L_0x007e;
    L_0x0075:
        r1 = c.j.a.c.g$d.b.a();	 Catch:{ all -> 0x00df }
        r4 = r0.a;	 Catch:{ all -> 0x00df }
        r1.b(r4);	 Catch:{ all -> 0x00df }
    L_0x007e:
        r0 = c.j.a.c.g$d.b.a();	 Catch:{ all -> 0x00df }
        r0.e(r9);	 Catch:{ all -> 0x00df }
        r0 = c.j.a.c.g.y.a();	 Catch:{ all -> 0x00df }
        r0 = c.j.a.d.b.e.i.a(r0);	 Catch:{ all -> 0x00df }
        r1 = "application/vnd.android.package-archive";
        r0 = r0.h(r1);	 Catch:{ all -> 0x00df }
        r0 = e(r0, r9);	 Catch:{ all -> 0x00df }
        if (r0 == 0) goto L_0x00c6;
    L_0x0099:
        r1 = r0.g0();	 Catch:{ all -> 0x00df }
        r1 = c.j.a.d.b.l.a.d(r1);	 Catch:{ all -> 0x00df }
        r4 = "no_hide_notification";
        r1 = r1.b(r4, r3);	 Catch:{ all -> 0x00df }
        if (r1 == r2) goto L_0x00b4;
    L_0x00a9:
        r1 = c.j.a.d.b.o.d.a();	 Catch:{ all -> 0x00df }
        r2 = r0.g0();	 Catch:{ all -> 0x00df }
        r1.b(r2);	 Catch:{ all -> 0x00df }
    L_0x00b4:
        r1 = c.j.a.c.x.b();	 Catch:{ all -> 0x00df }
        r2 = r1.a;	 Catch:{ all -> 0x00df }
        r3 = new c.j.a.c.v;	 Catch:{ all -> 0x00df }
        r3.m2313init(r1, r0, r9);	 Catch:{ all -> 0x00df }
        r2.post(r3);	 Catch:{ all -> 0x00df }
        c.j.a.c.g$i.c.b(r0);	 Catch:{ all -> 0x00df }
        goto L_0x00d5;
    L_0x00c6:
        r0 = c.j.a.c.x.b();	 Catch:{ all -> 0x00df }
        r1 = 0;
        r2 = r0.a;	 Catch:{ all -> 0x00df }
        r3 = new c.j.a.c.v;	 Catch:{ all -> 0x00df }
        r3.m2313init(r0, r1, r9);	 Catch:{ all -> 0x00df }
        r2.post(r3);	 Catch:{ all -> 0x00df }
    L_0x00d5:
        monitor-exit(r8);
        return;
    L_0x00d7:
        r9 = new java.lang.RuntimeException;	 Catch:{ all -> 0x00df }
        r0 = "handleAppInstalled in main thread.";
        r9.<init>(r0);	 Catch:{ all -> 0x00df }
        throw r9;	 Catch:{ all -> 0x00df }
    L_0x00df:
        r9 = move-exception;
        monitor-exit(r8);
        throw r9;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.g.m(java.lang.String):void");
    }

    public synchronized void q() {
        b bVar = this.b;
        if (bVar != null) {
            bVar.e = System.currentTimeMillis();
            this.b = null;
        }
    }
}
